Closed deshanxiao closed 10 months ago
What is the error? Are you getting corrupted data?
Technically, you should compress all data and then finish the encoding with length 0
.
I got no error but the output array looks unexpected in length. Here is a very simple example: @hyperxpro
public class Main2 {
static {
Brotli4jLoader.ensureAvailability();
}
public static void main(String[] args) throws IOException {
byte[] totalBytes = "abcdefg".getBytes();
// compress "defg"
byte[] compressedBytes = Encoder.compress(totalBytes, 3, 4);
// len(output) == 7 not 4
byte[] output = Decoder.decompress(compressedBytes, 0, compressedBytes.length);
}
}
Okay, looks like a bug.
Would you like to raise a PR at https://github.com/google/brotli?
Describe the bug Unable to compress correctly if input data does not start from 0.
To Reproduce Call Encoder.compress(byte[] x, int offset, int length) will compress all bytes from
x
(offset > 0)https://github.com/hyperxpro/Brotli4j/blob/0907a385873def839cb0b88132f62238255bc0d6/brotli4j/src/main/java/com/aayushatharva/brotli4j/encoder/Encoder.java#L73
data.length -> length ?
Expected behavior It should only compress the bytes from start to start + len.
Platform (please complete the following information): ubuntu
Additional context