kspalaiologos / bzip3

A better and stronger spiritual successor to BZip2.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use help: source include to my project

wangkaish opened this issue · comments

I add common.h libbz3.h libsais.h libbz3.c to my project,
code:

bz3_bound(PAGE_SIZE);

result undefined reference to `bz3_bound(unsigned long)'

How to fix it?

You need to properly link to libbz3, or, if you are using C++, you have to put extern "C" { } around the inclusion of the library.

Thank you. Now I run it success, when I try compress some data with the follow code, error "Segmentation fault" occurred at code

for (s32 i = 0; i < 4; ++i) *out++ = *in++;

    char *in = "Hello world 123, Hello world 123, Hello world 123, Hello world 123, Hello world 123, Hello world 123, Hello world 123, Hello world 123, Hello world 123, Hello world 123, Hello world 123, Hello world 123,";
    int len = strlen(in);

    bz3_state *state = bz3_new(1024 * 128);

    int n5 = bz3_encode_block(state, reinterpret_cast<uint8_t *>(in), len);
    int n6 = bz3_decode_block(state, reinterpret_cast<uint8_t *>(in), n5, len);
    log_debug("n6: ", n6);

By the way, is there any compress/decompress api like lz4/zstd? It seems write compressed data to dst directly? I dont know if bz3_encode_block is the seem as ZSTD_compressCCtx.

ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx,
                                     void* dst, size_t dstCapacity,
                               const void* src, size_t srcSize,
                                     int compressionLevel);

ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx,
                                       void* dst, size_t dstCapacity,
                                 const void* src, size_t srcSize);

Hi,

In C and C++ string constants are not writable: they are usually placed in the rodata section.

You can use the high level APIs from the header.

Hi,
I am participating in a competition, and I am more sensitive to performance, looking for a library with good compression rate and speed, so I want to use low level api, the follow code was successed run, but I dont know why there is no out parameter, instead of rewrite to in buffer ?

void test_bz3_low_level() {
    char *in = "Hello world 123, Hello world 123, Hello world 123, Hello world 123, Hello world 123, Hello world 123, Hello world 123, Hello world 123, Hello world 123, Hello world 123, Hello world 123, Hello world 123,";
    int len = strlen(in);
    char *in2 = new char[len];
    memcpy(in2, in, len);

    bz3_state *state = bz3_new(1024 * 128);

    int n5 = bz3_encode_block(state, reinterpret_cast<uint8_t *>(in2), len);
    log_debug(std::string (in2, n5));
    int n6 = bz3_decode_block(state, reinterpret_cast<uint8_t *>(in2), n5, len);
    log_debug(std::string (in2, n6));
    log_debug("n5: ", n5);
    log_debug("n6: ", n6);
}

Because that's the design of the low level API.