private void StartWorker(
            int threadIndex,
            long currentBlockOffset,
            byte[] dataToProcess,
            IReadOnlyList <CustomGzipFooter.CompressedChunkInfo> chunksToProcess,
            CancellationToken cancellationToken)
        {
            for (int i = 0; i < chunksToProcess.Count; i++)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }
                var currentChunk = chunksToProcess[i];

                var currentChunkStart = currentChunk.CompressedStart - currentBlockOffset;

                using (var input = new MemoryStream(dataToProcess, (int)currentChunkStart, (int)currentChunk.CompressedLength, false))
                {
                    // do not write directly to output...
                    using (var output = new MemoryStream())
                    {
                        GzipWrapper.Decompress(input, output);
                        lock (_writerLocker)
                        {
                            this._writerStream.Seek(currentChunk.OriginalStart, SeekOrigin.Begin);
                            output.WriteTo(_writerStream);
                        }
                    }
                }
            }
        }
        private void StartWorker()
        {
            while (this._chunkInfos.TryTake(out CustomGzipFooter.CompressedChunkInfo chunkInfo))
            {
                byte[] buffer = new byte[chunkInfo.CompressedLength];
                int    bytesRead;
                lock (this._readerLocker)
                {
                    this._readerStream.Seek(chunkInfo.CompressedStart, SeekOrigin.Begin);
                    bytesRead = _readerStream.Read(buffer, 0, (int)chunkInfo.CompressedLength);
                }

                var decompressed = GzipWrapper.Decompress(buffer, 0, bytesRead);

                lock (this._writerLocker)
                {
                    this._writerStream.Seek(chunkInfo.OriginalStart, SeekOrigin.Begin);
                    // decompresseed.Length should be the same as chunkInfo.OriginalLength
                    this._writerStream.Write(decompressed, 0, decompressed.Length);
                }
            }
        }
Пример #3
0
        private void StartWorker(int chunkSize, CancellationToken cancellationToken)
        {
            byte[] buffer = new byte[chunkSize];
            int    bytesRead;

            while ((bytesRead = ReadChunk(buffer, chunkSize, out long chunkStartPosition)) > 0)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }
                var compressed = GzipWrapper.Compress(buffer, 0, bytesRead);
                lock (_writerLocker)
                {
                    this._footer.AddChunkInfo(
                        originalStart: chunkStartPosition,
                        compressedStart: this._writerStream.Position,
                        originalLength: bytesRead,
                        compressedLength: compressed.Length);

                    this._writerStream.Write(compressed, 0, compressed.Length);
                }
            }
        }