public void Read(string fileName, MyCancellationToken cancellationToken) { using (var compressedFile = new FileStream(fileName, FileMode.Open)) { while (compressedFile.Position < compressedFile.Length && !cancellationToken.IsCancelled) { var lengthBuffer = new byte[8]; compressedFile.Read(lengthBuffer, 0, lengthBuffer.Length); var blockLength = BitConverter.ToInt32(lengthBuffer, 4); var compressedData = new byte[blockLength]; lengthBuffer.CopyTo(compressedData, 0); compressedFile.Read(compressedData, 8, blockLength - 8); int dataSize = BitConverter.ToInt32(compressedData, blockLength - 4); byte[] lastBuffer = new byte[dataSize]; var _block = new CompressedData { Buffer = compressedData, UncompressedSize = dataSize }; ConsoleIndicator.ShowProgress(compressedFile.Position, compressedFile.Length); _inputStorage.Add(_block); } _inputStorage.Close(); } }
public void Read(string fileName, MyCancellationToken cancellationToken) { using (var readFile = new FileStream(fileName, FileMode.Open)) { int bytesRead; while (readFile.Position < readFile.Length && !cancellationToken.IsCancelled) { if (readFile.Length - readFile.Position <= BlockSize) { bytesRead = (int)(readFile.Length - readFile.Position); } else { bytesRead = BlockSize; } var readBuffer = new byte[bytesRead]; readFile.Read(readBuffer, 0, bytesRead); ConsoleIndicator.ShowProgress(readFile.Position, readFile.Length); _inputStorage.Add(new DecompressedData { Buffer = readBuffer }); } _inputStorage.Close(); } }