コード例 #1
0
        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);
                        }
                    }
                }
            }
        }
コード例 #2
0
        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);
                }
            }
        }