public void Code(Stream inStream, Stream outStream, Int64 inSize, Int64 outSize, ICodeProgress progress) { if (_outWindow is null) { CreateDictionary(); } _outWindow.Init(outStream); if (outSize > 0) { _outWindow.SetLimit(outSize); } else { _outWindow.SetLimit(Int64.MaxValue - _outWindow._total); } RangeCoder.Decoder rangeDecoder = new RangeCoder.Decoder(); rangeDecoder.Init(inStream); Code(_dictionarySize, _outWindow, rangeDecoder); _outWindow.ReleaseStream(); rangeDecoder.ReleaseStream(); if (!rangeDecoder.IsFinished || (inSize > 0 && rangeDecoder._total != inSize)) { throw new DataErrorException(); } if (_outWindow.HasPending) { throw new DataErrorException(); } _outWindow = null; }
public void Code(Stream inStream, Stream outStream, Int64 inSize, Int64 outSize, ICodeProgress progress) { if (_outWindow is null) { CreateDictionary(); } _outWindow.Init(outStream); if (outSize > 0) { _outWindow.SetLimit(outSize); } else { _outWindow.SetLimit(Int64.MaxValue - _outWindow._total); } RangeCoder.Decoder rangeDecoder = new RangeCoder.Decoder(); rangeDecoder.Init(inStream); Code(_dictionarySize, _outWindow, rangeDecoder); _outWindow.ReleaseStream(); rangeDecoder.ReleaseStream(); _outWindow = null; }
public override int Read(byte[] buffer, int offset, int count) { if (endReached) { return(0); } int total = 0; while (total < count) { if (availableBytes == 0) { if (isLZMA2) { decodeChunkHeader(); } else { endReached = true; } if (endReached) { break; } } int toProcess = count - total; if (toProcess > availableBytes) { toProcess = (int)availableBytes; } outWindow.SetLimit(toProcess); if (uncompressedChunk) { inputPosition += outWindow.CopyStream(inputStream, toProcess); } else if (decoder.Code(dictionarySize, outWindow, rangeDecoder) && outputSize < 0) { availableBytes = outWindow.AvailableBytes; } int read = outWindow.Read(buffer, offset, toProcess); total += read; offset += read; position += read; availableBytes -= read; if (availableBytes == 0 && !uncompressedChunk) { rangeDecoder.ReleaseStream(); if (!rangeDecoder.IsFinished || (rangeDecoderLimit >= 0 && rangeDecoder.Total != rangeDecoderLimit)) { throw new DataErrorException(); } inputPosition += rangeDecoder.Total; if (outWindow.HasPending) { throw new DataErrorException(); } } } if (endReached) { if (inputSize >= 0 && inputPosition != inputSize) { throw new DataErrorException(); } if (outputSize >= 0 && position != outputSize) { throw new DataErrorException(); } } return(total); }
public override int Read(byte[] buffer, int offset, int count) { if (_endReached) { return(0); } int total = 0; while (total < count) { if (_availableBytes == 0) { if (_isLzma2) { DecodeChunkHeader(); } else { _endReached = true; } if (_endReached) { break; } } int toProcess = count - total; if (toProcess > _availableBytes) { toProcess = (int)_availableBytes; } _outWindow.SetLimit(toProcess); if (_uncompressedChunk) { _inputPosition += _outWindow.CopyStream(_inputStream, toProcess); } else if (_decoder.Code(_dictionarySize, _outWindow, _rangeDecoder) && _outputSize < 0) { _availableBytes = _outWindow.AvailableBytes; } int read = _outWindow.Read(buffer, offset, toProcess); total += read; offset += read; _position += read; _availableBytes -= read; if (_availableBytes == 0 && !_uncompressedChunk) { _rangeDecoder.ReleaseStream(); if (!_rangeDecoder.IsFinished || (_rangeDecoderLimit >= 0 && _rangeDecoder._total != _rangeDecoderLimit)) { throw new DataErrorException(); } _inputPosition += _rangeDecoder._total; if (_outWindow.HasPending) { throw new DataErrorException(); } } } if (_endReached) { if (_inputSize >= 0 && _inputPosition != _inputSize) { throw new DataErrorException(); } if (_outputSize >= 0 && _position != _outputSize) { throw new DataErrorException(); } } return(total); }