public void EncodeFile(string decodedFilePath, string encodedFilePath, int bufferSize) { var hasher = MD5.Create(); bool unixLineEnding = encodedFilePath.Contains("UnixLineEnding"); using (FileStream decodedFileStream = File.OpenRead(decodedFilePath)) { using (var unbuffered = new MemoryStream()) { using (var encodedStream = new BufferedStream(unbuffered, bufferSize)) { using (var encodeStream = new UUEncodeStream(encodedStream, unixLineEnding)) { decodedFileStream.CopyTo(encodeStream); } } byte[] actualEncoded = unbuffered.ToArray(); File.WriteAllBytes(encodedFilePath + ".actual", actualEncoded); byte[] expectedEncoded = Encoding.ASCII.GetBytes(File.ReadAllText(encodedFilePath)); string actualHash = BitConverter.ToString(hasher.ComputeHash(actualEncoded)); string expectedHash = BitConverter.ToString(hasher.ComputeHash(expectedEncoded)); if (actualHash != expectedHash) { for (int i = 0; i < expectedEncoded.Length; i++) { Assert.AreEqual(expectedEncoded[i], actualEncoded[i], "Byte values must match at postion {0}.", i); } } } } }
public void Benchmark() { var watch = Stopwatch.StartNew(); const string decodedFilePath = @"Files\UUTests-LargeWithUnixLineEnding.txt"; using (FileStream decodedFileStream = File.OpenRead(decodedFilePath)) { using (var encodeStream = new UUEncodeStream(new MemoryStream(), true)) { decodedFileStream.CopyTo(encodeStream); } } watch.Stop(); Assert.LessThan(watch.ElapsedMilliseconds, 500); }