public DecompressionStream(Stream stream, int bufferSize = 0) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } if (!stream.CanRead) { throw new ArgumentException("Stream is not readable", nameof(stream)); } if (bufferSize < 0) { throw new ArgumentOutOfRangeException(nameof(bufferSize)); } innerStream = stream; decompressor = new Decompressor(); inputBufferSize = bufferSize > 0 ? bufferSize : (int)Methods.ZSTD_CStreamInSize().EnsureZstdSuccess(); inputBuffer = ArrayPool <byte> .Shared.Rent(inputBufferSize); input = new ZSTD_inBuffer_s { pos = (nuint)inputBufferSize, size = (nuint)inputBufferSize }; }
protected override void Dispose(bool disposing) { if (decompressor == null) { return; } if (lastDecompressResult != 0) { throw new EndOfStreamException("Premature end of stream"); } decompressor.Dispose(); decompressor = null; ArrayPool <byte> .Shared.Return(inputBuffer); }