public ReadWriteCompressedStream(Stream inner) { _inner = inner ?? throw new ArgumentNullException(nameof(inner)); _input = ZstdStream.Decompress(inner); _output = ZstdStream.Compress(inner); _dispose = new DisposeOnce <SingleAttempt>(DisposeInternal); }
public unsafe ReadWriteCompressedStream(Stream inner, JsonOperationContext.MemoryBuffer alreadyOnBuffer) { Stream innerInput = inner; int valid = alreadyOnBuffer.Valid - alreadyOnBuffer.Used; if (valid > 0) { byte[] buffer = ArrayPool <byte> .Shared.Rent(valid); fixed(byte *pBuffer = buffer) { Memory.Copy(pBuffer, alreadyOnBuffer.Address + alreadyOnBuffer.Used, valid); } innerInput = new ConcatStream(new ConcatStream.RentedBuffer { Buffer = buffer, Offset = 0, Count = valid }, inner); alreadyOnBuffer.Valid = alreadyOnBuffer.Used = 0; // consume all the data from the buffer } _inner = innerInput ?? throw new ArgumentNullException(nameof(inner)); _input = ZstdStream.Decompress(inner); _output = ZstdStream.Compress(inner); _dispose = new DisposeOnce <SingleAttempt>(DisposeInternal); }