bz3_compress
papyrussolution opened this issue · comments
you didn't shift 'in' ptr in main loop after iteration :(
do something like what i showed below (my corrections marked as @sobolev - i had modified code a lot for myself)
// Compress and write the blocks.
size_t in_offs = 0; // @sobolev
for(uint32 i = 0; i < n_blocks; i++) {
int32 size = block_size;
if(i == (n_blocks - 1))
size = in_size % block_size;
memcpy(compression_buf, in+in_offs, size); // @sobolev in-->(in+in_offs)
int32 out_size_block = bz3_encode_block(state, compression_buf, size);
if(bz3_last_error(state) != BZ3_OK) {
int8 last_error = state->last_error;
bz3_free(state);
SAlloc::F(compression_buf);
return last_error;
}
memcpy(out + *out_size + 8, compression_buf, out_size_block);
write_neutral_s32(out + *out_size, out_size_block);
write_neutral_s32(out + *out_size + 4, size);
*out_size += out_size_block + 8;
in_offs += size; // @sobolev
}