/// <inheritdoc/> protected override void BaseCompress(Stream inputStream, Stream outputStream) { using var brotliStream = new Brotli.BrotliStream(outputStream, CompressionMode.Compress, true); brotliStream.SetQuality(Quality); brotliStream.SetWindow(Window); inputStream.CopyTo(brotliStream); inputStream.Flush(); brotliStream.Flush(); }
/// <inheritdoc/> protected override async Task BaseCompressAsync(Stream inputStream, Stream outputStream, CancellationToken cancellationToken = default) { using var brotliStream = new Brotli.BrotliStream(outputStream, CompressionMode.Compress, true); brotliStream.SetQuality(Quality); brotliStream.SetWindow(Window); await inputStream.CopyToAsync(brotliStream, DefaultBufferSize, cancellationToken).ConfigureAwait(false); await inputStream.FlushAsync(cancellationToken).ConfigureAwait(false); await brotliStream.FlushAsync(cancellationToken).ConfigureAwait(false); }
/// <inheritdoc/> protected override byte[] BaseCompress(byte[] bytes) { using var inputStream = new MemoryStream(bytes); using var outputStream = new MemoryStream(); using (var brotliStream = new Brotli.BrotliStream(outputStream, CompressionMode.Compress)) { brotliStream.SetQuality(Quality); brotliStream.SetWindow(Window); inputStream.CopyTo(brotliStream, bytes.Length); //inputStream.WriteTo(brotliStream); //brotliStream.Write(bytes, 0, bytes.Length); inputStream.Flush(); brotliStream.Flush(); } return outputStream.ToArray(); }