private void DoBlockByBlockWriting() { // Process while there is still remaining data in the stream while (true) { // Generate segment Segment segment = null; lock (source) { byte[] buffer = new byte[configuration.SegmentSize]; int readResult = source.Read(buffer, 0, buffer.Length); if (readResult > 0) { // Adjust buffer size to the stream length in case if we almost reached the end of it if (readResult < configuration.SegmentSize) { buffer = buffer.Take(readResult).ToArray(); } segment = dataSegmenter.GetSegment(++segmentId, buffer); } else { break; } } // Compress Segment lock (segmentStreamWriter) { segmentStreamWriter.Write(destination, segment); } } }
public void Write(Stream stream, Segment segment) { exceptionConsumingProcessor.Process(() => segmentStreamWriter.Write(stream, segment)); }