Skip to content

Commit

Permalink
fix BrotliCompressor
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Apr 12, 2024
1 parent f30eb95 commit c55e631
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/MemoryPack.Core/Compression/BrotliCompressor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,11 @@ static int CompressCore<TBufferWriter>(ref BrotliEncoder encoder, ReadOnlySpan<b
var totalWritten = 0;

var lastResult = OperationStatus.DestinationTooSmall;

var destLength = initialLength ?? BrotliUtils.BrotliEncoderMaxCompressedSize(source.Length);
while (lastResult == OperationStatus.DestinationTooSmall)
{
ref var spanRef = ref destBufferWriter.GetSpanReference(initialLength ?? source.Length);
ref var spanRef = ref destBufferWriter.GetSpanReference(destLength);
var dest = MemoryMarshal.CreateSpan(ref spanRef, destBufferWriter.BufferLength);

lastResult = encoder.Compress(source, dest, out int bytesConsumed, out int bytesWritten, isFinalBlock: isFinalBlock);
Expand Down

0 comments on commit c55e631

Please sign in to comment.