-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Description
I have some stream where it contains multiple zstd streams with other data in between, so I need to read the exact compressed buffer stream that I know the size of, and I seemingly can't use DecompressionStream because it will read data from stream up to its buffer size which may read past of my compressed size.
I can't really set stream buffer size to anything other than full compressed size, which would defeat the purpose of using the stream here.
My current non-stream code is this:
private static void DecompressZSTD(ZstdSharp.Decompressor zstdDecompressor, BinaryReader reader, Span<byte> output, int compressedSize)
{
var inputBuf = ArrayPool<byte>.Shared.Rent(compressedSize);
try
{
var input = inputBuf.AsSpan(0, compressedSize);
reader.Read(input);
if (!zstdDecompressor.TryUnwrap(input, output, out var written) || output.Length != written)
{
throw new InvalidDataException($"Failed to decompress ZSTD (expected {output.Length} bytes, got {written})");
}
}
finally
{
ArrayPool<byte>.Shared.Return(inputBuf);
}
}The issue is basically here, as it will read past my total compressed size to fill in the input buffer.
ZstdSharp/src/ZstdSharp/DecompressionStream.cs
Lines 129 to 131 in 511daf1
| // Otherwise, read some more input | |
| int bytesRead; | |
| if ((bytesRead = innerStream.Read(inputBuffer, 0, inputBufferSize)) == 0) |
Metadata
Metadata
Assignees
Labels
No labels