public override int Read(byte[] buffer, int offset, int count) { int requiredCount = count - offset; int remainingCount = requiredCount; for (; _chunkIndex < _stream.Chunks.Count && remainingCount > 0;) { IStreamChunk currentChunk = _stream.Chunks[_chunkIndex]; int currentChunkLength = currentChunk.Length - _chunkOffset; if (currentChunkLength > remainingCount) { currentChunkLength = remainingCount; } int currentReadCount = currentChunk.Stream.Read(buffer, offset, currentChunkLength); offset += currentReadCount; remainingCount -= currentReadCount; _chunkOffset += currentChunkLength; _position += currentReadCount; if (_chunkOffset >= currentChunk.Length) { _chunkOffset = 0; _chunkIndex++; } } return(requiredCount - remainingCount); }
protected virtual void ProcessInputStreamChunk(InputWorkItem workItem, IStreamChunk inputStreamChunk, Stream compressionStream) { using (Stream chunkStream = new BufferedStream(inputStreamChunk.Stream)) { byte[] buffer = new byte[inputStreamChunk.Length]; int readedBytes = inputStreamChunk.Stream.Read(buffer, 0, (int)inputStreamChunk.Length); if (readedBytes < inputStreamChunk.Length) { throw new CompressionException("Cannot read input stream"); } compressionStream.Write(buffer, 0, inputStreamChunk.Length); } }