public void WriteTest003() { string filePath = Path.Combine(Util.ArtifactsPath, "test042C.djvu"); string outFilePath = Path.Combine(Util.ArtifactsDataPath, Path.GetFileName(filePath) + ".2048.bz3"); string refFilePath = Path.Combine(Util.ArtifactsDataPath, Path.GetFileName(filePath) + ".2048.bzz"); try { byte[] buffer = Util.ReadFileToEnd(filePath); byte[] data = new byte[buffer.Length + 32]; Buffer.BlockCopy(buffer, 0, data, 0, buffer.Length); long bytesWritten = 0; using (Stream stream = new FileStream( outFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) using (BSOutputStream writer = new BSOutputStream(stream, 2048)) { writer.Write(data, 0, buffer.Length); bytesWritten = stream.Position; } byte[] testBuffer = Util.ReadFileToEnd(outFilePath); byte[] refBuffer = Util.ReadFileToEnd(refFilePath); Util.AssertBufferEqal(testBuffer, refBuffer); using (MemoryStream readStream = new MemoryStream(testBuffer)) using (BzzReader reader = new BzzReader(new BSInputStream(readStream))) { byte[] testResult = reader.ReadBytes(buffer.Length); Assert.NotNull(testResult); Assert.Equal(buffer.Length, testResult.Length); for (int i = 0; i < buffer.Length; i++) { Assert.Equal(buffer[i], testResult[i]); } } } finally { if (File.Exists(outFilePath)) { File.Delete(outFilePath); } } }
public void WriteTest002() { string filePath = Path.Combine(Util.ArtifactsDataPath, "DjvuNet.pdb"); string outFilePath = Path.GetTempFileName(); string refFilePath = filePath + ".bzz"; try { byte[] buffer = Util.ReadFileToEnd(filePath); byte[] data = new byte[buffer.Length + 32]; Buffer.BlockCopy(buffer, 0, data, 0, buffer.Length); long bytesWritten = 0; using (Stream stream = new FileStream( outFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) using (BSOutputStream writer = new BSOutputStream(stream, 4096)) { writer.Write(data, 0, buffer.Length); bytesWritten = stream.Position; } byte[] testBuffer = Util.ReadFileToEnd(outFilePath); byte[] refBuffer = Util.ReadFileToEnd(refFilePath); Util.AssertBufferEqal(testBuffer, refBuffer); using (MemoryStream readStream = new MemoryStream(testBuffer)) using (BzzReader reader = new BzzReader(new BSInputStream(readStream))) { byte[] testResult = reader.ReadBytes(buffer.Length); Assert.NotNull(testResult); Util.AssertBufferEqal(testResult, buffer); } } finally { if (File.Exists(outFilePath)) { File.Delete(outFilePath); } } }
public void WriteTest004() { string filePath = Path.Combine(Util.ArtifactsDataPath, "LLVMMCJIT.lib"); string outFilePath = Path.Combine(Util.ArtifactsDataPath, Path.GetFileName(filePath) + ".2048.bz3"); string refFilePath = Path.Combine(Util.ArtifactsDataPath, Path.GetFileName(filePath) + ".2048.bzz"); try { byte[] buffer = Util.ReadFileToEnd(filePath); long bytesWritten = 0; using (Stream stream = new FileStream( outFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) using (BSOutputStream writer = new BSOutputStream(stream, 2048)) { writer.Write(buffer, 0, buffer.Length); bytesWritten = stream.Position; } byte[] outputBuffer = Util.ReadFileToEnd(outFilePath); byte[] refBuffer = Util.ReadFileToEnd(refFilePath); Util.AssertBufferEqal(outputBuffer, refBuffer); using (FileStream readStream = new FileStream(outFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) using (BzzReader reader = new BzzReader(new BSInputStream(readStream))) { byte[] testResult = reader.ReadBytes(buffer.Length); Assert.NotNull(testResult); Util.AssertBufferEqal(testResult, buffer); } } finally { if (File.Exists(outFilePath)) { File.Delete(outFilePath); } } }