Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decompression output is not complete when using incremental #6

Open
orangefour opened this issue Dec 9, 2017 · 5 comments
Open

Decompression output is not complete when using incremental #6

orangefour opened this issue Dec 9, 2017 · 5 comments

Comments

@orangefour
Copy link

This test compresses and decompresses text by using incremental versions of the functions.

static void compress_decompress_incremental()
{
    const char* in_buffer = "Return a string containing a printable representation of an object. "
      "For many types, this function makes an attempt to return a string that would yield an "
      "object with the same value when passed to eval(), otherwise the representation is a "
      "string enclosed in angle brackets that contains the name of the type of the object "
      "together with additional information often including the name and address of the object.";

    uint8_t out_buffer[1024];
    LzsCompressParameters_t     compress_params;
    lzs_compress_init(&compress_params);

    compress_params.inPtr = (const uint8_t*)in_buffer;
    compress_params.inLength = strlen(in_buffer);
    compress_params.outPtr = out_buffer;
    compress_params.outLength = sizeof(out_buffer);

    size_t out_size = lzs_compress_incremental(&compress_params, true);

    char dec_buffer[1024];

    LzsDecompressParameters_t   decompress_params;
    lzs_decompress_init(&decompress_params);

    decompress_params.inPtr = out_buffer;
    decompress_params.inLength = out_size;
    decompress_params.outPtr = (uint8_t*)dec_buffer;
    decompress_params.outLength = sizeof(dec_buffer);

    size_t dec_size = lzs_decompress_incremental(&decompress_params);
    //dec_buffer[dec_size] = 0;

    printf("Decompressed data \n%s\n", dec_buffer);
}

Unfortunately after decompression, the last 3 words (of the object.) are missing.

@cmcqueen
Copy link
Owner

After calling lzs_compress_incremental(), examine which bit-flags are set in compress_params.status (refer to LzsCompressStatus_t). That will give you insight into the compression status.

Likewise for decompression, after calling lzs_decompress_incremental(), examine decompress_params.status bit-flags.

@cmcqueen
Copy link
Owner

In this case, the call to lzs_compress_incremental() returns with compress_params.status set to LZS_C_STATUS_INPUT_FINISHED | LZS_C_STATUS_INPUT_STARVED, indicating that all the input is used up. It is necessary to call the function a second time (again with the 2nd parameter set to true), which flushes remaining data and sets the LZS_C_STATUS_END_MARKER bit in the status.

@cmcqueen
Copy link
Owner

Please see the branch issue-6 for example.

@orangefour
Copy link
Author

Thank you for explanation and example! I played around and noticed sometimes I need to call lzs_compress_incremental() with 2nd parameter set to true multiple times before all the data gets flushed. This might not be what the average user expects (yeah I am just nagging 😁)

@cmcqueen
Copy link
Owner

I might be able to modify the function so that it completes outputting the end-marker in the first call to the function. I'll see what I can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants