diff options
Diffstat (limited to 'programs/lz4io.c')
-rw-r--r-- | programs/lz4io.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/programs/lz4io.c b/programs/lz4io.c index 49caed3..8bd10fc 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -149,7 +149,7 @@ static const int one = 1; //************************************** static int displayLevel = 0; // 0 : no display // 1: errors // 2 : + result + interaction + warnings ; // 3 : + progression; // 4 : + information static int overwrite = 1; -static int blockSizeId = LZ4S_BLOCKSIZEID_DEFAULT; +static int globalBlockSizeId = LZ4S_BLOCKSIZEID_DEFAULT; static int blockChecksum = 0; static int streamChecksum = 1; static int blockIndependence = 1; @@ -198,18 +198,16 @@ int LZ4IO_setBlockSizeID(int bsid) { static const int blockSizeTable[] = { 64 KB, 256 KB, 1 MB, 4 MB }; if ((bsid < minBlockSizeID) || (bsid > maxBlockSizeID)) return -1; - blockSizeId = bsid; - return blockSizeTable[blockSizeId-minBlockSizeID]; + globalBlockSizeId = bsid; + return blockSizeTable[globalBlockSizeId-minBlockSizeID]; } - int LZ4IO_setBlockMode(blockMode_t blockMode) { blockIndependence = (blockMode == independentBlocks); return blockIndependence; } - /* Default setting : no checksum */ int LZ4IO_setBlockChecksumMode(int xxhash) { @@ -217,7 +215,6 @@ int LZ4IO_setBlockChecksumMode(int xxhash) return blockChecksum; } - /* Default setting : checksum enabled */ int LZ4IO_setStreamChecksumMode(int xxhash) { @@ -225,7 +222,6 @@ int LZ4IO_setStreamChecksumMode(int xxhash) return streamChecksum; } - /* Default setting : 0 (no notification) */ int LZ4IO_setNotificationLevel(int level) { @@ -303,7 +299,6 @@ int LZ4IO_compressFilename_Legacy(char* input_filename, char* output_filename, i char* out_buff; FILE* finput; FILE* foutput; - int displayLevel = (compressionlevel>0); clock_t start, end; size_t sizeCheck; @@ -368,7 +363,7 @@ int LZ4IO_compressFilename_Legacy(char* input_filename, char* output_filename, i static void* LZ4IO_LZ4_createStream (const char* inputBuffer) { (void)inputBuffer; - return LZ4_createStream(); + return calloc(4, LZ4_STREAMSIZE_U32); } static int LZ4IO_LZ4_compress_limitedOutput_continue (void* ctx, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel) @@ -377,6 +372,11 @@ static int LZ4IO_LZ4_compress_limitedOutput_continue (void* ctx, const char* sou return LZ4_compress_limitedOutput_continue(ctx, source, dest, inputSize, maxOutputSize); } +static int LZ4IO_LZ4_saveDict (void* LZ4_stream, char* safeBuffer, int dictSize) +{ + return LZ4_saveDict ((LZ4_stream_t*) LZ4_stream, safeBuffer, dictSize); +} + static int LZ4IO_LZ4_slideInputBufferHC (void* ctx, char* buffer, int size) { (void)size; (void)buffer; @@ -385,6 +385,12 @@ static int LZ4IO_LZ4_slideInputBufferHC (void* ctx, char* buffer, int size) } +static int LZ4IO_free (void* ptr) +{ + free(ptr); + return 0; +} + static int compress_file_blockDependency(char* input_filename, char* output_filename, int compressionlevel) { void* (*initFunction) (const char*); @@ -412,19 +418,19 @@ static int compress_file_blockDependency(char* input_filename, char* output_file { initFunction = LZ4IO_LZ4_createStream; compressionFunction = LZ4IO_LZ4_compress_limitedOutput_continue; - nextBlockFunction = LZ4_saveDict; - freeFunction = LZ4_free; + nextBlockFunction = LZ4IO_LZ4_saveDict; + freeFunction = LZ4IO_free; } else { initFunction = LZ4_createHC; compressionFunction = LZ4_compressHC2_limitedOutput_continue; nextBlockFunction = LZ4IO_LZ4_slideInputBufferHC; - freeFunction = LZ4_free; + freeFunction = LZ4IO_free; } get_fileHandle(input_filename, output_filename, &finput, &foutput); - blockSize = LZ4S_GetBlockSize_FromBlockId (blockSizeId); + blockSize = LZ4S_GetBlockSize_FromBlockId (globalBlockSizeId); // Allocate Memory inputBufferSize = 64 KB + blockSize; @@ -442,7 +448,7 @@ static int compress_file_blockDependency(char* input_filename, char* output_file *(out_buff+4) |= (blockIndependence & _1BIT) << 5; *(out_buff+4) |= (blockChecksum & _1BIT) << 4; *(out_buff+4) |= (streamChecksum & _1BIT) << 2; - *(out_buff+5) = (char)((blockSizeId & _3BITS) << 4); + *(out_buff+5) = (char)((globalBlockSizeId & _3BITS) << 4); checkbits = XXH32((out_buff+4), 2, LZ4S_CHECKSUM_SEED); checkbits = LZ4S_GetCheckBits_FromXXH(checkbits); *(out_buff+6) = (unsigned char) checkbits; @@ -570,7 +576,7 @@ int LZ4IO_compressFilename(char* input_filename, char* output_filename, int comp if (compressionLevel <= 3) compressionFunction = LZ4_compress_limitedOutput_local; else { compressionFunction = LZ4_compressHC2_limitedOutput; } get_fileHandle(input_filename, output_filename, &finput, &foutput); - blockSize = LZ4S_GetBlockSize_FromBlockId (blockSizeId); + blockSize = LZ4S_GetBlockSize_FromBlockId (globalBlockSizeId); // Allocate Memory in_buff = (char*)malloc(blockSize); @@ -585,7 +591,7 @@ int LZ4IO_compressFilename(char* input_filename, char* output_filename, int comp *(headerBuffer+4) |= (blockIndependence & _1BIT) << 5; *(headerBuffer+4) |= (blockChecksum & _1BIT) << 4; *(headerBuffer+4) |= (streamChecksum & _1BIT) << 2; - *(headerBuffer+5) = (char)((blockSizeId & _3BITS) << 4); + *(headerBuffer+5) = (char)((globalBlockSizeId & _3BITS) << 4); checkbits = XXH32((headerBuffer+4), 2, LZ4S_CHECKSUM_SEED); checkbits = LZ4S_GetCheckBits_FromXXH(checkbits); *(headerBuffer+6) = (unsigned char) checkbits; @@ -749,7 +755,7 @@ static unsigned long long decodeLZ4S(FILE* finput, FILE* foutput) size_t sizeCheck; int blockChecksumFlag, streamChecksumFlag, blockIndependenceFlag; void* streamChecksumState=NULL; - int (*decompressionFunction)(void* ctx, const char* src, char* dst, int cSize, int maxOSize) = LZ4_decompress_safe_continue; + int (*decompressionFunction)(LZ4_streamDecode_t* ctx, const char* src, char* dst, int cSize, int maxOSize) = LZ4_decompress_safe_continue; LZ4_streamDecode_t ctx; // init @@ -841,7 +847,7 @@ static unsigned long long decodeLZ4S(FILE* finput, FILE* foutput) { // handle dictionary for streaming memcpy(in_buff + blockSize - 64 KB, out_buff, 64 KB); - LZ4_setDictDecode(&ctx, out_buff, 64 KB); + LZ4_setStreamDecode(&ctx, out_buff, 64 KB); out_start = out_buff + 64 KB; } } |