This pull request introduces public APIs to the LZ4Codec that introduce partial decompression support. Namely, it exposes the original LZ4's LZ4_decompress_safe_partial to the world.
The ability to perform partial decompression can be pretty useful in the presence of SOLID blocks; it's not currently here, but the ported code supports it; so I figure it'd be handy to expose it.
Added Public APIs
LZ4Codec
/// <summary>Decompresses data from the given buffer, stopping at <paramref name="targetLength"/>.</summary>
/// <param name="source">Input buffer.</param>
/// <param name="sourceLength">Input buffer length.</param>
/// <param name="target">Output buffer.</param>
/// <param name="targetLength">Output buffer length. Decoding stops at this amount.</param>
/// <returns>Number of bytes written, or a negative value if the output buffer is too small.</returns>
public static unsafe int DecodePartial(byte* source, int sourceLength, byte* target, int targetLength);
/// <summary>Decompresses data from the given buffer, stopping at the <paramref name="target"/> buffer length.</summary>
/// <param name="source">Input buffer.</param>
/// <param name="target">Output buffer. Decoding stops at the end of the buffer.</param>
/// <returns>Number of bytes written, or a negative value if the output buffer is too small.</returns>
public static unsafe int DecodePartial(ReadOnlySpan<byte> source, Span<byte> target);
I named these DecodePartial because the default is Decode, I wanted to keep the pattern from the original LZ4 library around.
Tests
Tests for partial decoding were added as PartialDecompressionTests.cs.
They cover a variety of test cases, including:
Decompression of full file (full decompression but with partial method call).
Partial decompression with prime numbers.
Miscellaneous
I made a minor fix for an incorrect error message in call to LZ4_decompress_safe_usingDict, when the function for the given target was not implemented.
About
This pull request introduces public APIs to the LZ4Codec that introduce partial decompression support. Namely, it exposes the original LZ4's
LZ4_decompress_safe_partial
to the world.The ability to perform partial decompression can be pretty useful in the presence of SOLID blocks; it's not currently here, but the ported code supports it; so I figure it'd be handy to expose it.
Added Public APIs
LZ4Codec
I named these
DecodePartial
because the default isDecode
, I wanted to keep the pattern from the original LZ4 library around.Tests
Tests for partial decoding were added as
PartialDecompressionTests.cs
.They cover a variety of test cases, including:
Miscellaneous
I made a minor fix for an incorrect error message in call to
LZ4_decompress_safe_usingDict
, when the function for the given target was not implemented.