summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/.gitignore1
-rw-r--r--examples/Makefile17
-rw-r--r--examples/blockStreaming_lineByLine.c2
-rw-r--r--examples/blockStreaming_lineByLine.md8
-rw-r--r--examples/compress_functions.c4
-rw-r--r--examples/dictionaryRandomAccess.c6
-rw-r--r--examples/dictionaryRandomAccess.md4
-rw-r--r--examples/fileCompress.c232
-rw-r--r--examples/frameCompress.c140
-rw-r--r--examples/simple_buffer.c6
-rw-r--r--examples/streaming_api_basics.md4
11 files changed, 378 insertions, 46 deletions
diff --git a/examples/.gitignore b/examples/.gitignore
index 5abeef6..ddc8e21 100644
--- a/examples/.gitignore
+++ b/examples/.gitignore
@@ -6,5 +6,6 @@
/ringBufferHC
/lineCompress
/frameCompress
+/fileCompress
/simpleBuffer
/*.exe
diff --git a/examples/Makefile b/examples/Makefile
index 3ec3e21..8be5c81 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -1,6 +1,6 @@
# ##########################################################################
# LZ4 examples - Makefile
-# Copyright (C) Yann Collet 2011-2014
+# Copyright (C) Yann Collet 2011-2020
#
# GPL v2 License
#
@@ -41,7 +41,7 @@ include ../Makefile.inc
default: all
all: printVersion doubleBuffer dictionaryRandomAccess ringBuffer ringBufferHC \
- lineCompress frameCompress simpleBuffer
+ lineCompress frameCompress fileCompress simpleBuffer
$(LZ4DIR)/liblz4.a: $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c $(LZ4DIR)/lz4frame.c $(LZ4DIR)/lz4.h $(LZ4DIR)/lz4hc.h $(LZ4DIR)/lz4frame.h $(LZ4DIR)/lz4frame_static.h
$(MAKE) -C $(LZ4DIR) liblz4.a
@@ -67,6 +67,9 @@ lineCompress: blockStreaming_lineByLine.c $(LZ4DIR)/liblz4.a
frameCompress: frameCompress.c $(LZ4DIR)/liblz4.a
$(CC) $(FLAGS) $^ -o $@$(EXT)
+fileCompress: fileCompress.c $(LZ4DIR)/liblz4.a
+ $(CC) $(FLAGS) $^ -o $@$(EXT)
+
compressFunctions: compress_functions.c $(LZ4DIR)/liblz4.a
$(CC) $(FLAGS) $^ -o $@$(EXT) -lrt
@@ -94,10 +97,18 @@ test : all $(LZ4)
@echo "\n=== Frame compression ==="
./frameCompress$(EXT) $(TESTFILE)
$(LZ4) -vt $(TESTFILE).lz4
+ @echo "\n=== file compression ==="
+ ./fileCompress$(EXT) $(TESTFILE)
+ $(LZ4) -vt $(TESTFILE).lz4
+
+.PHONY: cxxtest
+cxxtest: CFLAGS := -O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror
+cxxtest: clean
+ CC=$(CXX) $(MAKE) -C . all CFLAGS="$(CFLAGS)"
clean:
@rm -f core *.o *.dec *-0 *-9 *-8192 *.lz4s *.lz4 \
printVersion$(EXT) doubleBuffer$(EXT) dictionaryRandomAccess$(EXT) \
ringBuffer$(EXT) ringBufferHC$(EXT) lineCompress$(EXT) frameCompress$(EXT) \
- compressFunctions$(EXT) simpleBuffer$(EXT)
+ fileCompress$(EXT) compressFunctions$(EXT) simpleBuffer$(EXT)
@echo Cleaning completed
diff --git a/examples/blockStreaming_lineByLine.c b/examples/blockStreaming_lineByLine.c
index 19c3345..3047a3a 100644
--- a/examples/blockStreaming_lineByLine.c
+++ b/examples/blockStreaming_lineByLine.c
@@ -65,7 +65,7 @@ static void test_compress(
{
const int cmpBytes = LZ4_compress_fast_continue(
- lz4Stream, inpPtr, cmpBuf, inpBytes, cmpBufBytes, 1);
+ lz4Stream, inpPtr, cmpBuf, inpBytes, (int) cmpBufBytes, 1);
if (cmpBytes <= 0) break;
write_uint16(outFp, (uint16_t) cmpBytes);
write_bin(outFp, cmpBuf, cmpBytes);
diff --git a/examples/blockStreaming_lineByLine.md b/examples/blockStreaming_lineByLine.md
index 4735f92..7b66883 100644
--- a/examples/blockStreaming_lineByLine.md
+++ b/examples/blockStreaming_lineByLine.md
@@ -1,7 +1,7 @@
# LZ4 Streaming API Example : Line by Line Text Compression
by *Takayuki Matsuoka*
-`blockStreaming_lineByLine.c` is LZ4 Straming API example which implements line by line incremental (de)compression.
+`blockStreaming_lineByLine.c` is LZ4 Streaming API example which implements line by line incremental (de)compression.
Please note the following restrictions :
@@ -107,7 +107,7 @@ This is called "External Dictionary Mode".
In Line#X+2 (see (5)), finally LZ4 forget almost all memories but still remains Line#X+1.
This is the same situation as Line#2.
-Continue these procedure to the end of text file.
+Continue these procedures to the end of text file.
## How the decompression works
@@ -117,6 +117,6 @@ Decompression will do reverse order.
- Read compressed line from the file to buffer.
- Decompress it to the ringbuffer.
- Output decompressed plain text line to the file.
- - Forward ringbuffer offset. If offset exceedes end of the ringbuffer, reset it.
+ - Forward ringbuffer offset. If offset exceeds end of the ringbuffer, reset it.
-Continue these procedure to the end of the compressed file.
+Continue these procedures to the end of the compressed file.
diff --git a/examples/compress_functions.c b/examples/compress_functions.c
index 7fd6775..2a9d124 100644
--- a/examples/compress_functions.c
+++ b/examples/compress_functions.c
@@ -35,7 +35,7 @@
*
* LZ4_decompress_safe
* This is the recommended function for decompressing data. It is considered safe because the caller specifies
- * both the size of the compresssed buffer to read as well as the maximum size of the output (decompressed) buffer
+ * both the size of the compressed buffer to read as well as the maximum size of the output (decompressed) buffer
* instead of just the latter.
* LZ4_decompress_fast
* Again, despite its name it's not a "fast" version of decompression. It simply frees the caller of sending the
@@ -48,7 +48,7 @@
* Special Note About Decompression:
* Using the LZ4_decompress_safe() function protects against malicious (user) input. If you are using data from a
* trusted source, or if your program is the producer (P) as well as its consumer (C) in a PC or MPMC setup, you can
- * safely use the LZ4_decompress_fast function
+ * safely use the LZ4_decompress_fast function.
*/
/* Since lz4 compiles with c99 and not gnu/std99 we need to enable POSIX linking for time.h structs and functions. */
diff --git a/examples/dictionaryRandomAccess.c b/examples/dictionaryRandomAccess.c
index ecb3b2d..3aa4609 100644
--- a/examples/dictionaryRandomAccess.c
+++ b/examples/dictionaryRandomAccess.c
@@ -78,7 +78,7 @@ void test_compress(FILE* outFp, FILE* inpFp, void *dict, int dictSize)
}
/* Forget previously compressed data and load the dictionary */
- LZ4_loadDict(lz4Stream, dict, dictSize);
+ LZ4_loadDict(lz4Stream, (const char*) dict, dictSize);
{
char cmpBuf[LZ4_COMPRESSBOUND(BLOCK_BYTES)];
const int cmpBytes = LZ4_compress_fast_continue(
@@ -97,7 +97,7 @@ void test_compress(FILE* outFp, FILE* inpFp, void *dict, int dictSize)
while (ptr != offsetsEnd) {
write_int(outFp, *ptr++);
}
- write_int(outFp, offsetsEnd - offsets);
+ write_int(outFp, (int) (offsetsEnd - offsets));
}
}
@@ -153,7 +153,7 @@ void test_decompress(FILE* outFp, FILE* inpFp, void *dict, int dictSize, int off
}
/* Load the dictionary */
- LZ4_setStreamDecode(lz4StreamDecode, dict, dictSize);
+ LZ4_setStreamDecode(lz4StreamDecode, (const char*) dict, dictSize);
{
const int decBytes = LZ4_decompress_safe_continue(
lz4StreamDecode, cmpBuf, decBuf, cmpBytes, BLOCK_BYTES);
diff --git a/examples/dictionaryRandomAccess.md b/examples/dictionaryRandomAccess.md
index 53d825d..c6f4388 100644
--- a/examples/dictionaryRandomAccess.md
+++ b/examples/dictionaryRandomAccess.md
@@ -7,7 +7,7 @@ Please note that the output file is not compatible with lz4frame and is platform
## What's the point of this example ?
- - Dictionary based compression for homogenous files.
+ - Dictionary based compression for homogeneous files.
- Random access to compressed blocks.
@@ -64,4 +64,4 @@ Decompression will do reverse order.
- Read the next block.
- Decompress it and write that page to the file.
-Continue these procedure until all the required data has been read.
+Continue these procedures until all the required data has been read.
diff --git a/examples/fileCompress.c b/examples/fileCompress.c
new file mode 100644
index 0000000..4486ea8
--- /dev/null
+++ b/examples/fileCompress.c
@@ -0,0 +1,232 @@
+/* LZ4file API example : compress a file
+ * Modified from an example code by anjiahao
+ *
+ * This example will demonstrate how
+ * to manipulate lz4 compressed files like
+ * normal files */
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+
+#include <lz4file.h>
+
+
+#define CHUNK_SIZE (16*1024)
+
+static size_t get_file_size(char *filename)
+{
+ struct stat statbuf;
+
+ if (filename == NULL) {
+ return 0;
+ }
+
+ if(stat(filename,&statbuf)) {
+ return 0;
+ }
+
+ return statbuf.st_size;
+}
+
+static int compress_file(FILE* f_in, FILE* f_out)
+{
+ assert(f_in != NULL); assert(f_out != NULL);
+
+ LZ4F_errorCode_t ret = LZ4F_OK_NoError;
+ size_t len;
+ LZ4_writeFile_t* lz4fWrite;
+ void* const buf = malloc(CHUNK_SIZE);
+ if (!buf) {
+ printf("error: memory allocation failed \n");
+ }
+
+ /* Of course, you can also use prefsPtr to
+ * set the parameters of the compressed file
+ * NULL is use default
+ */
+ ret = LZ4F_writeOpen(&lz4fWrite, f_out, NULL);
+ if (LZ4F_isError(ret)) {
+ printf("LZ4F_writeOpen error: %s\n", LZ4F_getErrorName(ret));
+ free(buf);
+ return 1;
+ }
+
+ while (1) {
+ len = fread(buf, 1, CHUNK_SIZE, f_in);
+
+ if (ferror(f_in)) {
+ printf("fread error\n");
+ goto out;
+ }
+
+ /* nothing to read */
+ if (len == 0) {
+ break;
+ }
+
+ ret = LZ4F_write(lz4fWrite, buf, len);
+ if (LZ4F_isError(ret)) {
+ printf("LZ4F_write: %s\n", LZ4F_getErrorName(ret));
+ goto out;
+ }
+ }
+
+out:
+ free(buf);
+ if (LZ4F_isError(LZ4F_writeClose(lz4fWrite))) {
+ printf("LZ4F_writeClose: %s\n", LZ4F_getErrorName(ret));
+ return 1;
+ }
+
+ return 0;
+}
+
+static int decompress_file(FILE* f_in, FILE* f_out)
+{
+ assert(f_in != NULL); assert(f_out != NULL);
+
+ LZ4F_errorCode_t ret = LZ4F_OK_NoError;
+ LZ4_readFile_t* lz4fRead;
+ void* const buf= malloc(CHUNK_SIZE);
+ if (!buf) {
+ printf("error: memory allocation failed \n");
+ }
+
+ ret = LZ4F_readOpen(&lz4fRead, f_in);
+ if (LZ4F_isError(ret)) {
+ printf("LZ4F_readOpen error: %s\n", LZ4F_getErrorName(ret));
+ free(buf);
+ return 1;
+ }
+
+ while (1) {
+ ret = LZ4F_read(lz4fRead, buf, CHUNK_SIZE);
+ if (LZ4F_isError(ret)) {
+ printf("LZ4F_read error: %s\n", LZ4F_getErrorName(ret));
+ goto out;
+ }
+
+ /* nothing to read */
+ if (ret == 0) {
+ break;
+ }
+
+ if(fwrite(buf, 1, ret, f_out) != ret) {
+ printf("write error!\n");
+ goto out;
+ }
+ }
+
+out:
+ free(buf);
+ if (LZ4F_isError(LZ4F_readClose(lz4fRead))) {
+ printf("LZ4F_readClose: %s\n", LZ4F_getErrorName(ret));
+ return 1;
+ }
+
+ if (ret) {
+ return 1;
+ }
+
+ return 0;
+}
+
+int compareFiles(FILE* fp0, FILE* fp1)
+{
+ int result = 0;
+
+ while (result==0) {
+ char b0[1024];
+ char b1[1024];
+ size_t const r0 = fread(b0, 1, sizeof(b0), fp0);
+ size_t const r1 = fread(b1, 1, sizeof(b1), fp1);
+
+ result = (r0 != r1);
+ if (!r0 || !r1) break;
+ if (!result) result = memcmp(b0, b1, r0);
+ }
+
+ return result;
+}
+
+int main(int argc, const char **argv) {
+ char inpFilename[256] = { 0 };
+ char lz4Filename[256] = { 0 };
+ char decFilename[256] = { 0 };
+
+ if (argc < 2) {
+ printf("Please specify input filename\n");
+ return 0;
+ }
+
+ snprintf(inpFilename, 256, "%s", argv[1]);
+ snprintf(lz4Filename, 256, "%s.lz4", argv[1]);
+ snprintf(decFilename, 256, "%s.lz4.dec", argv[1]);
+
+ printf("inp = [%s]\n", inpFilename);
+ printf("lz4 = [%s]\n", lz4Filename);
+ printf("dec = [%s]\n", decFilename);
+
+ /* compress */
+ { FILE* const inpFp = fopen(inpFilename, "rb");
+ FILE* const outFp = fopen(lz4Filename, "wb");
+ printf("compress : %s -> %s\n", inpFilename, lz4Filename);
+ LZ4F_errorCode_t ret = compress_file(inpFp, outFp);
+ fclose(inpFp);
+ fclose(outFp);
+
+ if (ret) {
+ printf("compression error: %s\n", LZ4F_getErrorName(ret));
+ return 1;
+ }
+
+ printf("%s: %zu → %zu bytes, %.1f%%\n",
+ inpFilename,
+ get_file_size(inpFilename),
+ get_file_size(lz4Filename), /* might overflow is size_t is 32 bits and size_{in,out} > 4 GB */
+ (double)get_file_size(lz4Filename) / get_file_size(inpFilename) * 100);
+
+ printf("compress : done\n");
+ }
+
+ /* decompress */
+ {
+ FILE* const inpFp = fopen(lz4Filename, "rb");
+ FILE* const outFp = fopen(decFilename, "wb");
+
+ printf("decompress : %s -> %s\n", lz4Filename, decFilename);
+ LZ4F_errorCode_t ret = decompress_file(inpFp, outFp);
+
+ fclose(outFp);
+ fclose(inpFp);
+
+ if (ret) {
+ printf("compression error: %s\n", LZ4F_getErrorName(ret));
+ return 1;
+ }
+
+ printf("decompress : done\n");
+ }
+
+ /* verify */
+ { FILE* const inpFp = fopen(inpFilename, "rb");
+ FILE* const decFp = fopen(decFilename, "rb");
+
+ printf("verify : %s <-> %s\n", inpFilename, decFilename);
+ int const cmp = compareFiles(inpFp, decFp);
+
+ fclose(decFp);
+ fclose(inpFp);
+
+ if (cmp) {
+ printf("corruption detected : decompressed file differs from original\n");
+ return cmp;
+ }
+
+ printf("verify : OK\n");
+ }
+
+}
diff --git a/examples/frameCompress.c b/examples/frameCompress.c
index aac4a3b..25ff729 100644
--- a/examples/frameCompress.c
+++ b/examples/frameCompress.c
@@ -11,8 +11,9 @@
#include <errno.h>
#include <assert.h>
+#include <getopt.h>
#include <lz4frame.h>
-
+#include <lz4frame_static.h>
#define IN_CHUNK_SIZE (16*1024)
@@ -57,10 +58,11 @@ static compressResult_t
compress_file_internal(FILE* f_in, FILE* f_out,
LZ4F_compressionContext_t ctx,
void* inBuff, size_t inChunkSize,
- void* outBuff, size_t outCapacity)
+ void* outBuff, size_t outCapacity,
+ FILE* f_unc, long uncOffset)
{
compressResult_t result = { 1, 0, 0 }; /* result for an error */
- unsigned long long count_in = 0, count_out;
+ long long count_in = 0, count_out, bytesToOffset = -1;
assert(f_in != NULL); assert(f_out != NULL);
assert(ctx != NULL);
@@ -81,22 +83,48 @@ compress_file_internal(FILE* f_in, FILE* f_out,
/* stream file */
for (;;) {
- size_t const readSize = fread(inBuff, 1, IN_CHUNK_SIZE, f_in);
+ size_t compressedSize;
+ long long inSize = IN_CHUNK_SIZE;
+ if (uncOffset >= 0) {
+ bytesToOffset = uncOffset - count_in;
+
+ /* read only remaining bytes to offset position */
+ if (bytesToOffset < IN_CHUNK_SIZE && bytesToOffset > 0) {
+ inSize = bytesToOffset;
+ }
+ }
+
+ /* input data is at uncompressed data offset */
+ if (bytesToOffset <= 0 && uncOffset >= 0 && f_unc) {
+ size_t const readSize = fread(inBuff, 1, inSize, f_unc);
+ if (readSize == 0) {
+ uncOffset = -1;
+ continue;
+ }
+ count_in += readSize;
+ compressedSize = LZ4F_uncompressedUpdate(ctx,
+ outBuff, outCapacity,
+ inBuff, readSize,
+ NULL);
+ } else {
+ size_t const readSize = fread(inBuff, 1, inSize, f_in);
if (readSize == 0) break; /* nothing left to read from input file */
count_in += readSize;
-
- size_t const compressedSize = LZ4F_compressUpdate(ctx,
+ compressedSize = LZ4F_compressUpdate(ctx,
outBuff, outCapacity,
inBuff, readSize,
NULL);
- if (LZ4F_isError(compressedSize)) {
- printf("Compression failed: error %u \n", (unsigned)compressedSize);
- return result;
- }
- printf("Writing %u bytes\n", (unsigned)compressedSize);
- safe_fwrite(outBuff, 1, compressedSize, f_out);
- count_out += compressedSize;
+ }
+
+ if (LZ4F_isError(compressedSize)) {
+ printf("Compression failed: error %u \n", (unsigned)compressedSize);
+ return result;
+ }
+
+ printf("Writing %u bytes\n", (unsigned)compressedSize);
+ safe_fwrite(outBuff, 1, compressedSize, f_out);
+ count_out += compressedSize;
}
/* flush whatever remains within internal buffers */
@@ -120,12 +148,13 @@ compress_file_internal(FILE* f_in, FILE* f_out,
}
static compressResult_t
-compress_file(FILE* f_in, FILE* f_out)
+compress_file(FILE* f_in, FILE* f_out,
+ FILE* f_unc, int uncOffset)
{
assert(f_in != NULL);
assert(f_out != NULL);
- /* ressource allocation */
+ /* resource allocation */
LZ4F_compressionContext_t ctx;
size_t const ctxCreation = LZ4F_createCompressionContext(&ctx, LZ4F_VERSION);
void* const src = malloc(IN_CHUNK_SIZE);
@@ -137,9 +166,10 @@ compress_file(FILE* f_in, FILE* f_out)
result = compress_file_internal(f_in, f_out,
ctx,
src, IN_CHUNK_SIZE,
- outbuff, outbufCapacity);
+ outbuff, outbufCapacity,
+ f_unc, uncOffset);
} else {
- printf("error : ressource allocation failed \n");
+ printf("error : resource allocation failed \n");
}
LZ4F_freeCompressionContext(ctx); /* supports free on NULL */
@@ -286,7 +316,7 @@ static int decompress_file(FILE* f_in, FILE* f_out)
{
assert(f_in != NULL); assert(f_out != NULL);
- /* Ressource allocation */
+ /* Resource allocation */
void* const src = malloc(IN_CHUNK_SIZE);
if (!src) { perror("decompress_file(src)"); return 1; }
@@ -305,52 +335,106 @@ static int decompress_file(FILE* f_in, FILE* f_out)
}
-int compareFiles(FILE* fp0, FILE* fp1)
+int compareFiles(FILE* fp0, FILE* fp1, FILE* fpUnc, long uncOffset)
{
int result = 0;
+ long bytesRead = 0;
+ long bytesToOffset = -1;
+ long b1Size = 1024;
while (result==0) {
+ char b1[b1Size];
+ size_t r1;
+ size_t bytesToRead = sizeof b1;
+ if (uncOffset >= 0) {
+ bytesToOffset = uncOffset - bytesRead;
+
+ /* read remainder to offset */
+ if (bytesToOffset < b1Size) {
+ bytesToRead = bytesToOffset;
+ }
+ }
+
char b0[1024];
- char b1[1024];
- size_t const r0 = fread(b0, 1, sizeof(b0), fp0);
- size_t const r1 = fread(b1, 1, sizeof(b1), fp1);
+ size_t r0;
+ if (bytesToOffset <= 0 && fpUnc) {
+ bytesToRead = sizeof b1;
+ r0 = fread(b0, 1,bytesToRead, fpUnc);
+ } else {
+ r0 = fread(b0, 1, bytesToRead, fp0);
+ }
+
+ r1 = fread(b1, 1, r0, fp1);
result = (r0 != r1);
if (!r0 || !r1) break;
if (!result) result = memcmp(b0, b1, r0);
+
+ bytesRead += r1;
}
return result;
}
-int main(int argc, const char **argv) {
+int main(int argc, char **argv) {
char inpFilename[256] = { 0 };
char lz4Filename[256] = { 0 };
char decFilename[256] = { 0 };
+ int uncOffset = -1;
+ char uncFilename[256] = { 0 };
+ int opt;
+
if (argc < 2) {
printf("Please specify input filename\n");
- return 0;
+ return EXIT_FAILURE;
}
snprintf(inpFilename, 256, "%s", argv[1]);
snprintf(lz4Filename, 256, "%s.lz4", argv[1]);
snprintf(decFilename, 256, "%s.lz4.dec", argv[1]);
+ while ((opt = getopt(argc, argv, "o:d:")) != -1) {
+ switch (opt) {
+ case 'd':
+ snprintf(uncFilename, 256, "%s", optarg);
+ break;
+ case 'o':
+ uncOffset = atoi(optarg);
+ break;
+ default:
+ printf("usage: %s <input file> [-o <offset> -d <file>]\n", argv[0]);
+ printf("-o uncompressed data offset\n");
+ printf(" inject uncompressed data at this offset into the lz4 file\n");
+ printf("-d uncompressed file\n");
+ printf(" file to inject without compression into the lz4 file\n");
+ return EXIT_FAILURE;
+ }
+ }
+
printf("inp = [%s]\n", inpFilename);
printf("lz4 = [%s]\n", lz4Filename);
printf("dec = [%s]\n", decFilename);
+ if (uncOffset > 0) {
+ printf("unc = [%s]\n", uncFilename);
+ printf("ofs = [%i]\n", uncOffset);
+ }
/* compress */
{ FILE* const inpFp = fopen(inpFilename, "rb");
FILE* const outFp = fopen(lz4Filename, "wb");
+ FILE* const uncFp = fopen(uncFilename, "rb");
printf("compress : %s -> %s\n", inpFilename, lz4Filename);
- compressResult_t const ret = compress_file(inpFp, outFp);
+ compressResult_t const ret = compress_file(
+ inpFp, outFp,
+ uncFp, uncOffset);
fclose(outFp);
fclose(inpFp);
+ if (uncFp)
+ fclose(uncFp);
if (ret.error) {
printf("compress : failed with code %i\n", ret.error);
@@ -383,12 +467,16 @@ int main(int argc, const char **argv) {
/* verify */
{ FILE* const inpFp = fopen(inpFilename, "rb");
FILE* const decFp = fopen(decFilename, "rb");
+ FILE* const uncFp = fopen(uncFilename, "rb");
printf("verify : %s <-> %s\n", inpFilename, decFilename);
- int const cmp = compareFiles(inpFp, decFp);
+ int const cmp = compareFiles(inpFp, decFp,
+ uncFp, uncOffset);
fclose(decFp);
fclose(inpFp);
+ if (uncFp)
+ fclose(uncFp);
if (cmp) {
printf("corruption detected : decompressed file differs from original\n");
diff --git a/examples/simple_buffer.c b/examples/simple_buffer.c
index 6afc62a..f5c6eb2 100644
--- a/examples/simple_buffer.c
+++ b/examples/simple_buffer.c
@@ -44,10 +44,10 @@ int main(void) {
// LZ4 provides a function that will tell you the maximum size of compressed output based on input data via LZ4_compressBound().
const int max_dst_size = LZ4_compressBound(src_size);
// We will use that size for our destination boundary when allocating space.
- char* compressed_data = malloc((size_t)max_dst_size);
+ char* compressed_data = (char*)malloc((size_t)max_dst_size);
if (compressed_data == NULL)
run_screaming("Failed to allocate memory for *compressed_data.", 1);
- // That's all the information and preparation LZ4 needs to compress *src into *compressed_data.
+ // That's all the information and preparation LZ4 needs to compress *src into* compressed_data.
// Invoke LZ4_compress_default now with our size values and pointers to our memory locations.
// Save the return value for error checking.
const int compressed_data_size = LZ4_compress_default(src, compressed_data, src_size, max_dst_size);
@@ -73,7 +73,7 @@ int main(void) {
// Sometimes, the metadata can be extracted from the local context.
// First, let's create a *new_src location of size src_size since we know that value.
- char* const regen_buffer = malloc(src_size);
+ char* const regen_buffer = (char*)malloc(src_size);
if (regen_buffer == NULL)
run_screaming("Failed to allocate memory for *regen_buffer.", 1);
// The LZ4_decompress_safe function needs to know where the compressed data is, how many bytes long it is,
diff --git a/examples/streaming_api_basics.md b/examples/streaming_api_basics.md
index 1ccc6e3..6f5ae41 100644
--- a/examples/streaming_api_basics.md
+++ b/examples/streaming_api_basics.md
@@ -9,7 +9,7 @@ LZ4 has the following API sets :
It guarantees interoperability with other LZ4 framing format compliant tools/libraries
such as LZ4 command line utility, node-lz4, etc.
- "Block" API : This is recommended for simple purpose.
- It compress single raw memory block to LZ4 memory block and vice versa.
+ It compresses single raw memory block to LZ4 memory block and vice versa.
- "Streaming" API : This is designed for complex things.
For example, compress huge stream data in restricted memory environment.
@@ -22,7 +22,7 @@ But if you want to write advanced application, it's time to use Block or Streami
Block API (de)compresses a single contiguous memory block.
In other words, LZ4 library finds redundancy from a single contiguous memory block.
Streaming API does same thing but (de)compresses multiple adjacent contiguous memory blocks.
-So LZ4 library could find more redundancy than Block API.
+So Streaming API could find more redundancy than Block API.
The following figure shows difference between API and block sizes.
In these figures, the original data is split into 4KiBytes contiguous chunks.