/// <summary> /// Returns the chunks of current file that are NOT identical with the other file /// </summary> /// <param name="file">File to compare</param> /// <param name="chunkSize">Chunk size (Bytes)</param> /// <returns>Returns the chunks of current file that are NOT identical with the other file</returns> public IEnumerable<QuickIOFileChunk> GetFileChunksUnequal( QuickIOFileInfo file, Int32 chunkSize = DefaultChunkSize ) { var en1 = GetFileChunksEnumerator( chunkSize ); var en2 = file.GetFileChunksEnumerator( chunkSize ); while ( en1.MoveNext( ) ) { var mn2 = en2.MoveNext( ); // EOF of file2? if ( !mn2 ) { // current chunk must be unequal yield return en1.Current; } else { // check of the chunks are unequal if ( !en1.Current.ChunkEquals( en2.Current ) ) { // unequal yield return en1.Current; } } } }
/// <summary> /// Returns the chunks of current file that are NOT identical with the other file /// </summary> /// <param name="file">File to compare</param> /// <param name="chunkSize">Chunk size (Bytes)</param> /// <returns>Returns the chunks of current file that are NOT identical with the other file</returns> public IEnumerable <QuickIOFileChunk> GetFileChunksUnequal(QuickIOFileInfo file, Int32 chunkSize = DefaultChunkSize) { var en1 = GetFileChunksEnumerator(chunkSize); var en2 = file.GetFileChunksEnumerator(chunkSize); while (en1.MoveNext( )) { var mn2 = en2.MoveNext( ); // EOF of file2? if (!mn2) { // current chunk must be unequal yield return(en1.Current); } else { // check of the chunks are unequal if (!en1.Current.ChunkEquals(en2.Current)) { // unequal yield return(en1.Current); } } } }
/// <summary> /// Checks if both file contents are equal. /// Opens both files for read and breaks on first unequal chunk. /// </summary> /// <param name="file">File to compare</param> /// <param name="chunkSize">Chunk size (Bytes)</param> /// <returns>true if contents are equal</returns> public Boolean IsEqualContents(QuickIOFileInfo file, Int32 chunkSize = DefaultChunkSize) { var en1 = GetFileChunksEnumerator(chunkSize); var en2 = file.GetFileChunksEnumerator(chunkSize); while (true) { // Go to next element var mn1 = en1.MoveNext( ); var mn2 = en2.MoveNext( ); // check if next element exists if (mn1 != mn2) { // collections count diff return(false); } // no more elements in both collections if (!mn1) { return(true); } // check chunks var chunk1 = en1.Current; var chunk2 = en2.Current; if (!chunk1.ChunkEquals(chunk2)) { return(false); } } }
/// <summary> /// Returns the chunks of current file that are identical with the other file /// </summary> /// <param name="file">File to compare</param> /// <param name="chunkSize">Chunk size (Bytes)</param> /// <returns>Returns the chunks of current file that are identical with the other file</returns> public IEnumerable<QuickIOFileChunk> GetFileChunksEqual( QuickIOFileInfo file, Int32 chunkSize = DefaultChunkSize ) { var en1 = GetFileChunksEnumerator( chunkSize ); var en2 = file.GetFileChunksEnumerator( chunkSize ); while ( en1.MoveNext( ) && en2.MoveNext( ) ) { // check of the chunks are equal if ( en1.Current.ChunkEquals( en2.Current ) ) { // equal yield return en1.Current; } } }
/// <summary> /// Returns the chunks of current file that are identical with the other file /// </summary> /// <param name="file">File to compare</param> /// <param name="chunkSize">Chunk size (Bytes)</param> /// <returns>Returns the chunks of current file that are identical with the other file</returns> public IEnumerable <QuickIOFileChunk> GetFileChunksEqual(QuickIOFileInfo file, Int32 chunkSize = DefaultChunkSize) { var en1 = GetFileChunksEnumerator(chunkSize); var en2 = file.GetFileChunksEnumerator(chunkSize); while (en1.MoveNext( ) && en2.MoveNext( )) { // check of the chunks are equal if (en1.Current.ChunkEquals(en2.Current)) { // equal yield return(en1.Current); } } }
/// <summary> /// Checks if both file contents are equal. /// Opens both files for read and breaks on first unequal chunk. /// </summary> /// <param name="file">File to compare</param> /// <param name="chunkSize">Chunk size (Bytes)</param> /// <returns>true if contents are equal</returns> public Boolean IsEqualContents( QuickIOFileInfo file, Int32 chunkSize = DefaultChunkSize ) { var en1 = GetFileChunksEnumerator( chunkSize ); var en2 = file.GetFileChunksEnumerator( chunkSize ); while ( true ) { // Go to next element var mn1 = en1.MoveNext( ); var mn2 = en2.MoveNext( ); // check if next element exists if ( mn1 != mn2 ) { // collections count diff return false; } // no more elements in both collections if ( !mn1 ) { return true; } // check chunks var chunk1 = en1.Current; var chunk2 = en2.Current; if ( !chunk1.ChunkEquals( chunk2 ) ) { return false; } } }