Skip to content

Instantly share code, notes, and snippets.

@antopor
Created April 21, 2016 02:00
Show Gist options
  • Save antopor/b080da730540e8260ac15692435cc6bb to your computer and use it in GitHub Desktop.
Save antopor/b080da730540e8260ac15692435cc6bb to your computer and use it in GitHub Desktop.
lz4frame test program
#include <cstdlib>
#include <string>
#include <cassert>
#include "lz4frame.h"
const int data_size = 550 * 1024;
const int chunk_size = 256 * 1024;
void main()
{
// genearate some data
unsigned char data[data_size];
unsigned char *data_ptr = &data[0];
for (int i = 0; i < data_size; i++)
{
data[i] = std::rand();
}
// frame settings
LZ4F_preferences_t prefs;
memset(&prefs, 0, sizeof(prefs));
prefs.frameInfo.blockMode = blockIndependent;
prefs.frameInfo.blockSizeID = LZ4F_max256KB;
prefs.frameInfo.contentChecksumFlag = noContentChecksum;
prefs.compressionLevel = 1;
prefs.autoFlush = 0;
LZ4F_compressionContext_t ctx;
LZ4F_errorCode_t result = LZ4F_createCompressionContext(&ctx, LZ4F_VERSION);
assert(!LZ4F_isError(result));
size_t buffer_size = LZ4F_compressFrameBound(chunk_size, NULL);
void *buffer = malloc(buffer_size);
result = LZ4F_compressBegin(ctx, buffer, buffer_size, &prefs);
assert(!LZ4F_isError(result));
size_t bytes_to_write = LZ4F_compressUpdate(ctx, buffer, buffer_size, data_ptr, chunk_size, NULL);
assert(!LZ4F_isError(bytes_to_write));
result = LZ4F_compressEnd(ctx, buffer, buffer_size, NULL);
assert(!LZ4F_isError(result));
free(buffer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment