Skip to content

Commit

Permalink
Merge pull request #235 from Cysharp/hadashiA/expose-brotli-compresse…
Browse files Browse the repository at this point in the history
…d-size

Add method to get max compressed length to BrotliCompressor
  • Loading branch information
hadashiA authored Mar 14, 2024
2 parents 27feb86 + 5beb2c0 commit fb16a8b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/MemoryPack.Core/Compression/BrotliCompressor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ Span<byte> IBufferWriter<byte>.GetSpan(int sizeHint)
return bufferWriter.GetSpan(sizeHint);
}

public int GetMaxCompressedLength()
{
ThrowIfDisposed();
return BrotliUtils.BrotliEncoderMaxCompressedSize(bufferWriter.TotalWritten);
}

public byte[] ToArray()
{
ThrowIfDisposed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ Span<byte> IBufferWriter<byte>.GetSpan(int sizeHint)
return bufferWriter.GetSpan(sizeHint);
}

public int GetMaxCompressedLength()
{
ThrowIfDisposed();
return BrotliUtils.BrotliEncoderMaxCompressedSize(bufferWriter.TotalWritten);
}

public byte[] ToArray()
{
ThrowIfDisposed();
Expand Down Expand Up @@ -334,5 +340,5 @@ internal static int BrotliEncoderMaxCompressedSize(int input_size)
return (result < input_size) ? 0 : result;
}
}


}

0 comments on commit fb16a8b

Please sign in to comment.