summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml1
-rw-r--r--Makefile10
-rwxr-xr-xlz4.c160
-rw-r--r--lz4.h32
-rw-r--r--programs/Makefile15
-rw-r--r--programs/lz4cli.c2
-rw-r--r--programs/lz4io.c55
7 files changed, 163 insertions, 112 deletions
diff --git a/.travis.yml b/.travis.yml
index 2880427..472ca18 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,6 +4,7 @@ script: make test
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq gcc-multilib
+ - sudo apt-get install -qq valgrind
env:
- LZ4_TRAVIS_CI_ENV=-m32
diff --git a/Makefile b/Makefile
index c80e02c..ede6844 100644
--- a/Makefile
+++ b/Makefile
@@ -105,25 +105,25 @@ clean:
@echo Cleaning completed
-#make install option is reserved to Linux & OSX targets
+#make install option is designed for Linux & OSX targets only
ifneq (,$(filter $(shell uname),Linux Darwin))
install: liblz4
@install -d -m 755 $(DESTDIR)$(LIBDIR)/ $(DESTDIR)$(INCLUDEDIR)/
- @install -m 755 liblz4.a $(DESTDIR)$(LIBDIR)/liblz4.a
@install -m 755 liblz4.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_VER)
@cp -a liblz4.$(SHARED_EXT_MAJOR) $(DESTDIR)$(LIBDIR)
@cp -a liblz4.$(SHARED_EXT) $(DESTDIR)$(LIBDIR)
- @install -m 755 lz4.h $(DESTDIR)$(INCLUDEDIR)/lz4.h
- @install -m 755 lz4hc.h $(DESTDIR)$(INCLUDEDIR)/lz4hc.h
+ @install -m 644 liblz4.a $(DESTDIR)$(LIBDIR)/liblz4.a
+ @install -m 644 lz4.h $(DESTDIR)$(INCLUDEDIR)/lz4.h
+ @install -m 644 lz4hc.h $(DESTDIR)$(INCLUDEDIR)/lz4hc.h
@echo lz4 static and shared library installed
@cd $(PRGDIR); $(MAKE) -e install
uninstall:
- [ -x $(DESTDIR)$(LIBDIR)/liblz4.a ] && rm -f $(DESTDIR)$(LIBDIR)/liblz4.a
rm -f $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT)
rm -f $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_MAJOR)
[ -x $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_VER) ] && rm -f $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_VER)
+ [ -f $(DESTDIR)$(LIBDIR)/liblz4.a ] && rm -f $(DESTDIR)$(LIBDIR)/liblz4.a
[ -f $(DESTDIR)$(INCLUDEDIR)/lz4.h ] && rm -f $(DESTDIR)$(INCLUDEDIR)/lz4.h
[ -f $(DESTDIR)$(INCLUDEDIR)/lz4hc.h ] && rm -f $(DESTDIR)$(INCLUDEDIR)/lz4hc.h
@echo lz4 libraries successfully uninstalled
diff --git a/lz4.c b/lz4.c
index cb5c3db..2b37c69 100755
--- a/lz4.c
+++ b/lz4.c
@@ -240,14 +240,10 @@ typedef struct {
U32 currentOffset;
U32 initCheck;
const BYTE* dictionary;
+ const BYTE* bufferStart;
U32 dictSize;
} LZ4_dict_t_internal;
-typedef struct {
- LZ4_dict_t_internal dict;
- const BYTE* bufferStart;
-} LZ4_Data_Structure;
-
typedef enum { notLimited = 0, limitedOutput = 1 } limitedOutput_directive;
typedef enum { byPtr, byU32, byU16 } tableType_t;
@@ -415,7 +411,6 @@ static unsigned LZ4_count(const BYTE* pIn, const BYTE* pRef, const BYTE* pInLimi
return (unsigned)(pIn - pStart);
}
-
static int LZ4_compress_generic(
void* ctx,
const char* source,
@@ -445,7 +440,7 @@ static int LZ4_compress_generic(
const int skipStrength = SKIPSTRENGTH;
U32 forwardH;
- U16 delta=0;
+ size_t delta=0;
/* Init conditions */
if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported input size, too large (or negative) */
@@ -491,7 +486,7 @@ static int LZ4_compress_generic(
ref = LZ4_getPositionOnHash(h, ctx, tableType, base);
if (dict==usingExtDict)
{
- delta = (U16)(ip-ref);
+ delta = (ip-ref);
if (ref<(const BYTE*)source)
{
ref += dictDelta;
@@ -503,7 +498,9 @@ static int LZ4_compress_generic(
forwardH = LZ4_hashPosition(forwardIp, tableType);
LZ4_putPositionOnHash(ip, h, ctx, tableType, base);
- } while ((ref + MAX_DISTANCE < ip) || (A32(ref) != A32(ip)));
+ } while (((dict==usingExtDict) && (delta>MAX_DISTANCE)) ||
+ ((dict!=usingExtDict) && (ref + MAX_DISTANCE < ip)) ||
+ (A32(ref) != A32(ip)) );
/* Catch up */
while ((ip>anchor) && (ref > lowLimit) && (unlikely(ip[-1]==ref[-1]))) { ip--; ref--; }
@@ -578,7 +575,7 @@ _next_match:
ref = LZ4_getPosition(ip, ctx, tableType, base);
if (dict==usingExtDict)
{
- delta = (U16)(ip-ref);
+ delta = ip-ref;
if (ref<(const BYTE*)source)
{
ref += dictDelta;
@@ -587,7 +584,9 @@ _next_match:
else lowLimit = (const BYTE*)source;
}
LZ4_putPosition(ip, ctx, tableType, base);
- if ((ref + MAX_DISTANCE >= ip) && (A32(ref) == A32(ip))) { token = op++; *token=0; goto _next_match; }
+ if ((((dict==usingExtDict) && (delta<=MAX_DISTANCE)) ||
+ ((dict!=usingExtDict) && (ref + MAX_DISTANCE >= ip))) &&
+ (A32(ref) == A32(ip))) { token = op++; *token=0; goto _next_match; }
/* Prepare next loop */
forwardH = LZ4_hashPosition(++ip, tableType);
@@ -685,7 +684,21 @@ int LZ4_compress_limitedOutput_withState (void* state, const char* source, char*
Experimental : Streaming functions
*****************************************/
-int LZ4_loadDict (LZ4_dict_t* LZ4_dict, const char* dictionary, int dictSize)
+void* LZ4_createStream()
+{
+ void* lz4s = ALLOCATOR(4, LZ4_DICTSIZE_U32);
+ MEM_INIT(lz4s, 0, LZ4_DICTSIZE);
+ return lz4s;
+}
+
+int LZ4_free (void* LZ4_stream)
+{
+ FREEMEM(LZ4_stream);
+ return (0);
+}
+
+
+int LZ4_loadDict (void* LZ4_dict, const char* dictionary, int dictSize)
{
LZ4_dict_t_internal* dict = (LZ4_dict_t_internal*) LZ4_dict;
const BYTE* p = (const BYTE*)dictionary;
@@ -732,12 +745,13 @@ void LZ4_renormDictT(LZ4_dict_t_internal* LZ4_dict, const BYTE* src)
else LZ4_dict->hashTable[i] -= delta;
}
LZ4_dict->currentOffset = 64 KB;
- LZ4_dict->dictionary = src - 64 KB;
+ LZ4_dict->dictionary = LZ4_dict->dictionary + LZ4_dict->dictSize - 64 KB;
+ LZ4_dict->dictSize = 64 KB;
}
}
-int LZ4_compress_usingDict (LZ4_dict_t* LZ4_dict, const char* source, char* dest, int inputSize)
+int LZ4_compress_usingDict (void* LZ4_dict, const char* source, char* dest, int inputSize)
{
LZ4_dict_t_internal* streamPtr = (LZ4_dict_t_internal*)LZ4_dict;
const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize;
@@ -763,7 +777,7 @@ int LZ4_compress_usingDict (LZ4_dict_t* LZ4_dict, const char* source, char* dest
}
}
-int LZ4_compress_limitedOutput_usingDict (LZ4_dict_t* LZ4_dict, const char* source, char* dest, int inputSize, int maxOutputSize)
+int LZ4_compress_limitedOutput_usingDict (void* LZ4_dict, const char* source, char* dest, int inputSize, int maxOutputSize)
{
LZ4_dict_t_internal* streamPtr = (LZ4_dict_t_internal*)LZ4_dict;
const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize;
@@ -790,11 +804,71 @@ int LZ4_compress_limitedOutput_usingDict (LZ4_dict_t* LZ4_dict, const char* sour
}
+int LZ4_compress_continue (void* LZ4_stream, const char* source, char* dest, int inputSize)
+{
+ LZ4_dict_t_internal* streamPtr = (LZ4_dict_t_internal*)LZ4_stream;
+ const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize;
+
+ const BYTE* smallest = dictEnd;
+ if (smallest > (const BYTE*) source) smallest = (const BYTE*) source;
+ LZ4_renormDictT(streamPtr, smallest);
+
+ if (dictEnd == (const BYTE*)source)
+ {
+ int result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, 0, notLimited, byU32, withPrefix64k);
+ streamPtr->dictSize += (U32)inputSize;
+ streamPtr->currentOffset += (U32)inputSize;
+ return result;
+ }
+
+ {
+ int result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, 0, notLimited, byU32, usingExtDict);
+ streamPtr->dictionary = (const BYTE*)source;
+ streamPtr->dictSize = (U32)inputSize;
+ streamPtr->currentOffset += (U32)inputSize;
+ return result;
+ }
+}
+
+int LZ4_compress_limitedOutput_continue (void* LZ4_stream, const char* source, char* dest, int inputSize, int maxOutputSize)
+{
+ LZ4_dict_t_internal* streamPtr = (LZ4_dict_t_internal*)LZ4_stream;
+ const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize;
+
+ const BYTE* smallest = dictEnd;
+ if (smallest > (const BYTE*) source) smallest = (const BYTE*) source;
+ LZ4_renormDictT((LZ4_dict_t_internal*)LZ4_stream, smallest);
+
+ if (dictEnd == (const BYTE*)source)
+ {
+ int result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, withPrefix64k);
+ streamPtr->dictSize += (U32)inputSize;
+ streamPtr->currentOffset += (U32)inputSize;
+ return result;
+ }
+
+ {
+ int result = LZ4_compress_generic(LZ4_stream, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, usingExtDict);
+ streamPtr->dictionary = (const BYTE*)source;
+ streamPtr->dictSize = (U32)inputSize;
+ streamPtr->currentOffset += (U32)inputSize;
+ return result;
+ }
+}
+
+
// Hidden debug function, to force separate dictionary mode
int LZ4_compress_forceExtDict (LZ4_dict_t* LZ4_dict, const char* source, char* dest, int inputSize)
{
LZ4_dict_t_internal* streamPtr = (LZ4_dict_t_internal*)LZ4_dict;
- int result = LZ4_compress_generic(LZ4_dict, source, dest, inputSize, 0, notLimited, byU32, usingExtDict);
+ int result;
+ const BYTE* const dictEnd = streamPtr->dictionary + streamPtr->dictSize;
+
+ const BYTE* smallest = dictEnd;
+ if (smallest > (const BYTE*) source) smallest = (const BYTE*) source;
+ LZ4_renormDictT((LZ4_dict_t_internal*)LZ4_dict, smallest);
+
+ result = LZ4_compress_generic(LZ4_dict, source, dest, inputSize, 0, notLimited, byU32, usingExtDict);
streamPtr->dictionary = (const BYTE*)source;
streamPtr->dictSize = (U32)inputSize;
@@ -804,7 +878,7 @@ int LZ4_compress_forceExtDict (LZ4_dict_t* LZ4_dict, const char* source, char* d
}
-int LZ4_moveDict (LZ4_dict_t* LZ4_dict, char* safeBuffer, int dictSize)
+int LZ4_moveDict (void* LZ4_dict, char* safeBuffer, int dictSize)
{
LZ4_dict_t_internal* dict = (LZ4_dict_t_internal*) LZ4_dict;
const BYTE* previousDictEnd = dict->dictionary + dict->dictSize;
@@ -1044,18 +1118,23 @@ int LZ4_decompress_fast_usingDict(const char* source, char* dest, int originalSi
Obsolete Functions
**************************************/
/*
-These functions are deprecated and should no longer be used.
-They are provided here for compatibility with existing user programs.
+These function names are deprecated and should no longer be used.
+They are only provided here for compatibility with older user programs.
+- LZ4_uncompress is totally equivalent to LZ4_decompress_fast
+- LZ4_uncompress_unknownOutputSize is totally equivalent to LZ4_decompress_safe
*/
int LZ4_uncompress (const char* source, char* dest, int outputSize) { return LZ4_decompress_fast(source, dest, outputSize); }
int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize) { return LZ4_decompress_safe(source, dest, isize, maxOutputSize); }
+
/* Obsolete Streaming functions */
-int LZ4_sizeofStreamState()
-{
- return sizeof(LZ4_Data_Structure);
-}
+typedef struct {
+ LZ4_dict_t_internal dict;
+ const BYTE* bufferStart;
+} LZ4_Data_Structure;
+
+int LZ4_sizeofStreamState() { return sizeof(LZ4_Data_Structure); }
void LZ4_init(LZ4_Data_Structure* lz4ds, const BYTE* base)
{
@@ -1077,12 +1156,6 @@ void* LZ4_create (const char* inputBuffer)
return lz4ds;
}
-int LZ4_free (void* LZ4_Data)
-{
- FREEMEM(LZ4_Data);
- return (0);
-}
-
char* LZ4_slideInputBuffer (void* LZ4_Data)
{
@@ -1094,32 +1167,3 @@ char* LZ4_slideInputBuffer (void* LZ4_Data)
}
-int LZ4_compress_continue (void* LZ4_Data, const char* source, char* dest, int inputSize)
-{
- LZ4_dict_t_internal* streamPtr = (LZ4_dict_t_internal*)LZ4_Data;
- int result;
-
- LZ4_renormDictT(streamPtr, (const BYTE*) source);
- result = LZ4_compress_generic(LZ4_Data, source, dest, inputSize, 0, notLimited, byU32, withPrefix64k);
-
- if (streamPtr->dictSize == 0) streamPtr->dictionary = (const BYTE*)source;
- streamPtr->dictSize += (U32)inputSize;
- streamPtr->currentOffset += (U32)inputSize;
-
- return result;
-}
-
-int LZ4_compress_limitedOutput_continue (void* LZ4_Data, const char* source, char* dest, int inputSize, int maxOutputSize)
-{
- LZ4_dict_t_internal* streamPtr = (LZ4_dict_t_internal*)LZ4_Data;
- int result;
-
- LZ4_renormDictT(streamPtr, (const BYTE*) source);
- result = LZ4_compress_generic(LZ4_Data, source, dest, inputSize, maxOutputSize, limitedOutput, byU32, withPrefix64k);
-
- if (streamPtr->dictSize == 0) streamPtr->dictionary = (const BYTE*)source;
- streamPtr->dictSize += (U32)inputSize;
- streamPtr->currentOffset += (U32)inputSize;
-
- return result;
-}
diff --git a/lz4.h b/lz4.h
index 8a7db0c..7e38a54 100644
--- a/lz4.h
+++ b/lz4.h
@@ -170,45 +170,54 @@ int LZ4_compress_limitedOutput_withState (void* state, const char* source, char*
Experimental Streaming Functions
**************************************/
-#define LZ4_DICTSIZE_U32 ((1 << (LZ4_MEMORY_USAGE-2)) + 6)
+#define LZ4_DICTSIZE_U32 ((1 << (LZ4_MEMORY_USAGE-2)) + 8)
#define LZ4_DICTSIZE (LZ4_DICTSIZE_U32 * sizeof(unsigned int))
/*
* LZ4_dict_t
- * information structure to track an LZ4 stream
- * use LZ4_loadDict() (or set it to zero) to init it before first use.
+ * information structure to track an LZ4 stream.
+ * set it to zero, or use LZ4_loadDict() to init it before first use.
*/
typedef struct { unsigned int table[LZ4_DICTSIZE_U32]; } LZ4_dict_t;
+
+/*
+ * LZ4_createStream
+ * provides a pointer (void*) towards an initialized LZ4_dict_t structure
+ */
+void* LZ4_createStream();
+int LZ4_free (void* LZ4_stream);
+
/*
* LZ4_loadDict
* Use this function to load a static dictionary into LZ4_dict.
* You can load a size of 0 to init an LZ4_dict_t structure
* Return : 1 if OK, 0 if error
*/
-int LZ4_loadDict (LZ4_dict_t* LZ4_dict, const char* dictionary, int dictSize);
+int LZ4_loadDict (void* LZ4_stream, const char* dictionary, int dictSize);
/*
* LZ4_compress_usingDict
* Compress data block 'source', using blocks compressed before to improve compression ratio
* Previous data blocks are assumed to still be present at their previous location.
*/
-int LZ4_compress_usingDict (LZ4_dict_t* LZ4_dict, const char* source, char* dest, int inputSize);
+int LZ4_compress_usingDict (void* LZ4_stream, const char* source, char* dest, int inputSize);
/*
* LZ4_compress_limitedOutput_usingDict
* Same as before, but also specify a maximum target compressed size (maxOutputSize)
* If it cannot be met, compression exits, and return a zero.
*/
-int LZ4_compress_limitedOutput_usingDict (LZ4_dict_t* LZ4_dict, const char* source, char* dest, int inputSize, int maxOutputSize);
+int LZ4_compress_limitedOutput_usingDict (void* LZ4_stream, const char* source, char* dest, int inputSize, int maxOutputSize);
/*
* LZ4_moveDict
- * If previous data block cannot be guaranteed to remain at its previous location in memory
+ * If previously compressed data block is not guaranteed to remain at its previous memory location
* save it into a safe place (char* safeBuffer)
* before calling again LZ4_compress_usingDict()
* Return : 1 if OK, 0 if error
+ * Note : any dictSize > 64 KB will be interpreted as 64KB.
*/
-int LZ4_moveDict (LZ4_dict_t* LZ4_dict, char* safeBuffer, int dictSize);
+int LZ4_moveDict (void* LZ4_stream, char* safeBuffer, int dictSize);
/*
@@ -235,8 +244,10 @@ int LZ4_decompress_fast_withPrefix64k (const char* source, char* dest, int origi
Obsolete Functions
**************************************/
/*
-These functions are deprecated and should no longer be used.
-They are provided here for compatibility with existing user programs.
+These function names are deprecated and should no longer be used.
+They are only provided here for compatibility with older user programs.
+- LZ4_uncompress is totally equivalent to LZ4_decompress_fast
+- LZ4_uncompress_unknownOutputSize is totally equivalent to LZ4_decompress_safe
*/
int LZ4_uncompress (const char* source, char* dest, int outputSize);
int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
@@ -248,7 +259,6 @@ int LZ4_resetStreamState(void* state, const char* inputBuffer);
int LZ4_compress_continue (void* LZ4_Data, const char* source, char* dest, int inputSize);
int LZ4_compress_limitedOutput_continue (void* LZ4_Data, const char* source, char* dest, int inputSize, int maxOutputSize);
char* LZ4_slideInputBuffer (void* LZ4_Data);
-int LZ4_free (void* LZ4_Data);
#if defined (__cplusplus)
diff --git a/programs/Makefile b/programs/Makefile
index 522850e..53e4eb2 100644
--- a/programs/Makefile
+++ b/programs/Makefile
@@ -127,21 +127,21 @@ uninstall:
test: $(TEST_TARGETS)
-test-64: test-lz4 test-lz4c test-fullbench test-fuzzer
+test-64: test-lz4 test-lz4c test-fullbench test-fuzzer test-mem
-test-32: test-lz4 test-lz4c32 test-fullbench32 test-fuzzer32
+test-32: test-lz4 test-lz4c32 test-fullbench32 test-fuzzer32 test-mem32
test-lz4: lz4 datagen
./datagen | ./lz4 | ./lz4 -vdq > $(VOID)
./datagen -g256MB | ./lz4 -B4D | ./lz4 -vdq > $(VOID)
- ./datagen -g6GB | ./lz4 -vqBD | ./lz4 -vdq > $(VOID)
+ ./datagen -g6GB | ./lz4 -vqB5D | ./lz4 -vdq > $(VOID)
test-lz4c: lz4c datagen
test-lz4c32: lz4c32 datagen
./datagen | ./lz4c32 | ./lz4c32 -vdq > $(VOID)
./datagen -g256MB | ./lz4c32 -B4D | ./lz4c32 -vdq > $(VOID)
- ./datagen -g6GB | ./lz4c32 -vqBD | ./lz4c32 -vdq > $(VOID)
+ ./datagen -g6GB | ./lz4c32 -vqB5D | ./lz4c32 -vdq > $(VOID)
test-fullbench: fullbench
./fullbench --no-prompt $(BENCH_NB) $(TEST_FILES)
@@ -155,5 +155,12 @@ test-fuzzer: fuzzer
test-fuzzer32: fuzzer32
./fuzzer32 --no-prompt
+test-mem: lz4 datagen
+ ./datagen -g256M > tmp
+ valgrind ./lz4 -B4D -f tmp /dev/null
+ rm tmp
+
+test-mem32: lz4c32 datagen
+# unfortunately, valgrind doesn't work with non-native binary. If someone knows how to valgrind-test a 32-bits exe on a 64-bits system...
endif
diff --git a/programs/lz4cli.c b/programs/lz4cli.c
index 1c4e9de..e05a9a9 100644
--- a/programs/lz4cli.c
+++ b/programs/lz4cli.c
@@ -109,7 +109,7 @@
//****************************
#define COMPRESSOR_NAME "LZ4 Compression CLI"
#ifndef LZ4_VERSION
-# define LZ4_VERSION "v1.1.5"
+# define LZ4_VERSION "v1.1.8"
#endif
#define AUTHOR "Yann Collet"
#define WELCOME_MESSAGE "*** %s %i-bits %s, by %s (%s) ***\n", COMPRESSOR_NAME, (int)(sizeof(void*)*8), LZ4_VERSION, AUTHOR, __DATE__
diff --git a/programs/lz4io.c b/programs/lz4io.c
index 05955cf..e035f01 100644
--- a/programs/lz4io.c
+++ b/programs/lz4io.c
@@ -365,17 +365,16 @@ int LZ4IO_compressFilename_Legacy(char* input_filename, char* output_filename, i
}
-static int compress_file_blockDependency(char* input_filename, char* output_filename, int compressionlevel)
+static int compress_file_blockDependency2(char* input_filename, char* output_filename, int compressionlevel)
{
- void* (*initFunction) (const char*);
+ void* (*initFunction) ();
int (*compressionFunction)(void*, const char*, char*, int, int);
- char* (*translateFunction) (void*);
int (*freeFunction) (void*);
void* ctx;
unsigned long long filesize = 0;
unsigned long long compressedfilesize = 0;
unsigned int checkbits;
- char* in_buff, *in_start, *in_end;
+ char* in_buff, *in_blockStart, *in_end;
char* out_buff;
FILE* finput;
FILE* foutput;
@@ -384,24 +383,14 @@ static int compress_file_blockDependency(char* input_filename, char* output_file
size_t sizeCheck, header_size;
void* streamChecksumState=NULL;
-
// Init
start = clock();
if ((displayLevel==2) && (compressionlevel>=3)) displayLevel=3;
- if (compressionlevel>=3)
- {
- initFunction = LZ4_createHC;
- compressionFunction = LZ4_compressHC_limitedOutput_continue;
- translateFunction = LZ4_slideInputBufferHC;
- freeFunction = LZ4_freeHC;
- }
- else
- {
- initFunction = LZ4_create;
- compressionFunction = LZ4_compress_limitedOutput_continue;
- translateFunction = LZ4_slideInputBuffer;
- freeFunction = LZ4_free;
- }
+
+ initFunction = LZ4_createStream;
+ compressionFunction = LZ4_compress_limitedOutput_continue;
+ freeFunction = LZ4_free;
+
get_fileHandle(input_filename, output_filename, &finput, &foutput);
blockSize = LZ4S_GetBlockSize_FromBlockId (blockSizeId);
@@ -411,9 +400,9 @@ static int compress_file_blockDependency(char* input_filename, char* output_file
in_buff = (char*)malloc(inputBufferSize);
out_buff = (char*)malloc(blockSize+CACHELINE);
if (!in_buff || !out_buff) EXM_THROW(31, "Allocation error : not enough memory");
- in_start = in_buff; in_end = in_buff + inputBufferSize;
+ in_blockStart = in_buff; in_end = in_buff + inputBufferSize;
if (streamChecksum) streamChecksumState = XXH32_init(LZ4S_CHECKSUM_SEED);
- ctx = initFunction(in_buff);
+ ctx = initFunction();
// Write Archive Header
*(unsigned int*)out_buff = LITTLE_ENDIAN_32(LZ4S_MAGICNUMBER); // Magic Number, in Little Endian convention
@@ -435,19 +424,20 @@ static int compress_file_blockDependency(char* input_filename, char* output_file
{
unsigned int outSize;
unsigned int inSize;
+
// Read Block
- if ((in_start+blockSize) > in_end) in_start = translateFunction(ctx);
- inSize = (unsigned int) fread(in_start, (size_t)1, (size_t)blockSize, finput);
+ if ((in_blockStart+blockSize) > in_end) in_blockStart = in_buff;
+ inSize = (unsigned int) fread(in_blockStart, (size_t)1, (size_t)blockSize, finput);
if( inSize==0 ) break; // No more input : end of compression
filesize += inSize;
DISPLAYLEVEL(3, "\rRead : %i MB ", (int)(filesize>>20));
- if (streamChecksum) XXH32_update(streamChecksumState, in_start, inSize);
+ if (streamChecksum) XXH32_update(streamChecksumState, in_blockStart, inSize);
// Compress Block
- outSize = compressionFunction(ctx, in_start, out_buff+4, inSize, inSize-1);
+ outSize = compressionFunction(ctx, in_blockStart, out_buff+4, inSize, inSize-1);
if (outSize > 0) compressedfilesize += outSize+4; else compressedfilesize += inSize+4;
if (blockChecksum) compressedfilesize+=4;
- DISPLAYLEVEL(3, "\rRead : %i MB ==> %.2f%% ", (int)(filesize>>20), (double)compressedfilesize/filesize*100);
+ DISPLAYLEVEL(3, "==> %.2f%% ", (double)compressedfilesize/filesize*100);
// Write Block
if (outSize > 0)
@@ -462,24 +452,23 @@ static int compress_file_blockDependency(char* input_filename, char* output_file
sizeToWrite = 4 + outSize + (4*blockChecksum);
sizeCheck = fwrite(out_buff, 1, sizeToWrite, foutput);
if (sizeCheck!=(size_t)(sizeToWrite)) EXM_THROW(33, "Write error : cannot write compressed block");
-
}
else // Copy Original
{
* (unsigned int*) out_buff = LITTLE_ENDIAN_32(inSize|0x80000000); // Add Uncompressed flag
sizeCheck = fwrite(out_buff, 1, 4, foutput);
if (sizeCheck!=(size_t)(4)) EXM_THROW(34, "Write error : cannot write block header");
- sizeCheck = fwrite(in_start, 1, inSize, foutput);
+ sizeCheck = fwrite(in_blockStart, 1, inSize, foutput);
if (sizeCheck!=(size_t)(inSize)) EXM_THROW(35, "Write error : cannot write block");
if (blockChecksum)
{
- unsigned int checksum = XXH32(in_start, inSize, LZ4S_CHECKSUM_SEED);
+ unsigned int checksum = XXH32(in_blockStart, inSize, LZ4S_CHECKSUM_SEED);
* (unsigned int*) out_buff = LITTLE_ENDIAN_32(checksum);
sizeCheck = fwrite(out_buff, 1, 4, foutput);
if (sizeCheck!=(size_t)(4)) EXM_THROW(36, "Write error : cannot write block checksum");
}
}
- in_start += inSize;
+ in_blockStart += inSize;
}
// End of Stream mark
@@ -537,12 +526,12 @@ int LZ4IO_compressFilename(char* input_filename, char* output_filename, int comp
void* streamChecksumState=NULL;
// Branch out
- if (blockIndependence==0) return compress_file_blockDependency(input_filename, output_filename, compressionLevel);
+ if (blockIndependence==0) return compress_file_blockDependency2(input_filename, output_filename, compressionLevel);
// Init
start = clock();
if ((displayLevel==2) && (compressionLevel>=3)) displayLevel=3;
- if (compressionLevel <= 3) compressionFunction = LZ4_compress_limitedOutput_local;
+ 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);
@@ -587,7 +576,7 @@ int LZ4IO_compressFilename(char* input_filename, char* output_filename, int comp
outSize = compressionFunction(in_buff, out_buff+4, (int)readSize, (int)readSize-1, compressionLevel);
if (outSize > 0) compressedfilesize += outSize+4; else compressedfilesize += readSize+4;
if (blockChecksum) compressedfilesize+=4;
- DISPLAYLEVEL(3, "\rRead : %i MB ==> %.2f%% ", (int)(filesize>>20), (double)compressedfilesize/filesize*100);
+ DISPLAYLEVEL(3, "==> %.2f%% ", (double)compressedfilesize/filesize*100);
// Write Block
if (outSize > 0)