Repository navigation
Closed
Description
Provide an API for streaming compression/decompression in the same form as is done for Brotli in .NET standard library. This will allow ZstdSharp to be used in scenarios where Stream cannot be used (like System.IO.Pipelines).
BrotliDecoder:
/// <summary>Decompresses data that was compressed using the Brotli algorithm.</summary>
/// <param name="source">A buffer containing the compressed data.</param>
/// <param name="destination">When this method returns, a byte span containing the decompressed data.</param>
/// <param name="bytesConsumed">The total number of bytes that were read from <paramref name="source" />.</param>
/// <param name="bytesWritten">The total number of bytes that were written in the <paramref name="destination" />.</param>
/// <returns>One of the enumeration values that indicates the status of the decompression operation.</returns>
/// <remarks>The return value can be as follows:
/// - <see cref="System.Buffers.OperationStatus.Done" />: <paramref name="source" /> was successfully and completely decompressed into <paramref name="destination" />.
/// - <see cref="System.Buffers.OperationStatus.DestinationTooSmall" />: There is not enough space in <paramref name="destination" /> to decompress <paramref name="source" />.
/// - <see cref="System.Buffers.OperationStatus.NeedMoreData" />: The decompression action is partially done at least one more byte is required to complete the decompression task. This method should be called again with more input to decompress.
/// - <see cref="System.Buffers.OperationStatus.InvalidData" />: The data in <paramref name="source" /> is invalid and could not be decompressed.</remarks>
public OperationStatus Decompress(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesConsumed, out int bytesWritten);BrotliEncoder:
/// <summary>Compresses an empty read-only span of bytes into its destination, which ensures that output is produced for all the processed input. An actual flush is performed when the source is depleted and there is enough space in the destination for the remaining data.</summary>
/// <param name="destination">When this method returns, a span of bytes where the compressed data will be stored.</param>
/// <param name="bytesWritten">When this method returns, the total number of bytes that were written to <paramref name="destination" />.</param>
/// <returns>One of the enumeration values that describes the status with which the operation finished.</returns>
public OperationStatus Flush(Span<byte> destination, out int bytesWritten);
/// <summary>Compresses a read-only byte span into a destination span.</summary>
/// <param name="source">A read-only span of bytes containing the source data to compress.</param>
/// <param name="destination">When this method returns, a byte span where the compressed is stored.</param>
/// <param name="bytesConsumed">When this method returns, the total number of bytes that were read from <paramref name="source" />.</param>
/// <param name="bytesWritten">When this method returns, the total number of bytes that were written to <paramref name="destination" />.</param>
/// <param name="isFinalBlock"><see langword="true" /> to finalize the internal stream, which prevents adding more input data when this method returns; <see langword="false" /> to allow the encoder to postpone the production of output until it has processed enough input.</param>
/// <returns>One of the enumeration values that describes the status with which the span-based operation finished.</returns>
public OperationStatus Compress(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesConsumed, out int bytesWritten, bool isFinalBlock);Reacted by Juho Hanhimäki
Metadata
Metadata
Assignees
Labels
No labels
Activity
oleg-st commentedon Dec 25, 2025
I think it's a good idea.
oleg-st commentedon Dec 25, 2025
Draft implementation
#64
oleg-st commentedon Jan 2, 2026
Added in master
oleg-st commentedon Jan 3, 2026
Released in 0.8.7
deniszykov commentedon Jan 4, 2026