public void DecodeFile(string decodedFilePath, string encodedFilePath, int bufferSize) { var hasher = MD5.Create(); using (FileStream encodedFileStream = File.OpenRead(encodedFilePath)) { using (var decodeStream = new UUDecodeStream(encodedFileStream)) { using (var unbuffered = new MemoryStream()) { using (var decodedFileStream = new BufferedStream(unbuffered, bufferSize)) { decodeStream.CopyTo(decodedFileStream); } byte[] actualDecoded = unbuffered.ToArray(); File.WriteAllBytes(decodedFilePath + ".actual", actualDecoded); byte[] expectedDecoded = Encoding.ASCII.GetBytes(File.ReadAllText(decodedFilePath)); Assert.AreEqual(expectedDecoded.Length, actualDecoded.Length); string actualHash = BitConverter.ToString(hasher.ComputeHash(actualDecoded)); string expectedHash = BitConverter.ToString(hasher.ComputeHash(expectedDecoded)); if (actualHash != expectedHash) { for (int i = 0; i < expectedDecoded.Length; i++) { Assert.AreEqual(expectedDecoded[i], actualDecoded[i], "Byte values must match at postiion {0}.", i); } } } } } }
public void Benchmark() { var watch = Stopwatch.StartNew(); const string encodedFilePath = @"Files\UUTests-LargeWithUnixLineEnding.uue"; using (FileStream encodedFileStream = File.OpenRead(encodedFilePath)) { using (var decodeStream = new UUDecodeStream(encodedFileStream)) { using (var decodedStream = new MemoryStream()) { decodeStream.CopyTo(decodedStream); } } } watch.Stop(); Assert.LessThan(watch.ElapsedMilliseconds, 500); }