diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/HCStreaming_ringBuffer.c | 9 | ||||
-rw-r--r-- | examples/Makefile | 13 | ||||
-rw-r--r-- | examples/blockStreaming_doubleBuffer.c | 2 | ||||
-rw-r--r-- | examples/blockStreaming_doubleBuffer.md | 6 | ||||
-rw-r--r-- | examples/blockStreaming_lineByLine.c | 2 | ||||
-rw-r--r-- | examples/compress_functions.c | 26 | ||||
-rw-r--r-- | examples/dictionaryRandomAccess.c | 4 | ||||
-rw-r--r-- | examples/frameCompress.c | 25 | ||||
-rw-r--r-- | examples/simple_buffer.c | 55 | ||||
-rw-r--r-- | examples/streaming_api_basics.md | 12 |
10 files changed, 77 insertions, 77 deletions
diff --git a/examples/HCStreaming_ringBuffer.c b/examples/HCStreaming_ringBuffer.c index a878577..bc8391e 100644 --- a/examples/HCStreaming_ringBuffer.c +++ b/examples/HCStreaming_ringBuffer.c @@ -26,6 +26,7 @@ #include <stdint.h> #include <stdlib.h> #include <string.h> +#include <assert.h> enum { MESSAGE_MAX_BYTES = 1024, @@ -39,7 +40,8 @@ size_t write_int32(FILE* fp, int32_t i) { } size_t write_bin(FILE* fp, const void* array, int arrayBytes) { - return fwrite(array, 1, arrayBytes, fp); + assert(arrayBytes >= 0); + return fwrite(array, 1, (size_t)arrayBytes, fp); } size_t read_int32(FILE* fp, int32_t* i) { @@ -47,7 +49,8 @@ size_t read_int32(FILE* fp, int32_t* i) { } size_t read_bin(FILE* fp, void* array, int arrayBytes) { - return fread(array, 1, arrayBytes, fp); + assert(arrayBytes >= 0); + return fread(array, 1, (size_t)arrayBytes, fp); } @@ -174,7 +177,7 @@ int main(int argc, const char** argv) return 0; } - if (!strcmp(argv[1], "-p")) pause = 1, fileID = 2; + if (!strcmp(argv[1], "-p")) { pause = 1; fileID = 2; } snprintf(inpFilename, 256, "%s", argv[fileID]); snprintf(lz4Filename, 256, "%s.lz4s-%d", argv[fileID], 9); diff --git a/examples/Makefile b/examples/Makefile index 103e7ec..3ec3e21 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -19,7 +19,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # You can contact the author at : -# - LZ4 source repository : https://github.com/Cyan4973/lz4 +# - LZ4 source repository : https://github.com/lz4/lz4 # - LZ4 forum froup : https://groups.google.com/forum/#!forum/lz4c # ########################################################################## # This makefile compile and test @@ -36,16 +36,7 @@ TESTFILE = Makefile LZ4DIR := ../lib LZ4 = ../programs/lz4 - -# Define *.exe as extension for Windows systems -ifneq (,$(filter Windows%,$(OS))) -EXT =.exe -VOID = nul -else -EXT = -VOID = /dev/null -endif - +include ../Makefile.inc default: all diff --git a/examples/blockStreaming_doubleBuffer.c b/examples/blockStreaming_doubleBuffer.c index acb3455..3f719d3 100644 --- a/examples/blockStreaming_doubleBuffer.c +++ b/examples/blockStreaming_doubleBuffer.c @@ -44,7 +44,7 @@ void test_compress(FILE* outFp, FILE* inpFp) char inpBuf[2][BLOCK_BYTES]; int inpBufIndex = 0; - LZ4_resetStream(lz4Stream); + LZ4_initStream(lz4Stream, sizeof (*lz4Stream)); for(;;) { char* const inpPtr = inpBuf[inpBufIndex]; diff --git a/examples/blockStreaming_doubleBuffer.md b/examples/blockStreaming_doubleBuffer.md index 3027ea3..38dc2e8 100644 --- a/examples/blockStreaming_doubleBuffer.md +++ b/examples/blockStreaming_doubleBuffer.md @@ -1,7 +1,7 @@ # LZ4 Streaming API Example : Double Buffer by *Takayuki Matsuoka* -`blockStreaming_doubleBuffer.c` is LZ4 Straming API example which implements double buffer (de)compression. +`blockStreaming_doubleBuffer.c` is LZ4 Streaming API example which implements double buffer (de)compression. Please note : @@ -76,10 +76,10 @@ so it just compress the line without dependencies and generates compressed block After that, write {Out#1} to the file. Next, read second block to double buffer's second page. And compress it. -In this time, LZ4 can use dependency to Block#1 to improve compression ratio. +This time, LZ4 can use dependency to Block#1 to improve compression ratio. This dependency is called "Prefix mode". -Next, read third block to double buffer's *first* page. And compress it. +Next, read third block to double buffer's *first* page, and compress it. Also this time, LZ4 can use dependency to Block#2. This dependency is called "External Dictonaly mode". diff --git a/examples/blockStreaming_lineByLine.c b/examples/blockStreaming_lineByLine.c index 677c426..19c3345 100644 --- a/examples/blockStreaming_lineByLine.c +++ b/examples/blockStreaming_lineByLine.c @@ -99,7 +99,7 @@ static void test_decompress( uint16_t cmpBytes = 0; if (read_uint16(inpFp, &cmpBytes) != 1) break; - if (cmpBytes <= 0) break; + if (cmpBytes == 0) break; if (read_bin(inpFp, cmpBuf, cmpBytes) != cmpBytes) break; { diff --git a/examples/compress_functions.c b/examples/compress_functions.c index d0dca13..7fd6775 100644 --- a/examples/compress_functions.c +++ b/examples/compress_functions.c @@ -60,6 +60,7 @@ #define _POSIX_C_SOURCE 199309L /* Includes, for Power! */ +#define LZ4_DISABLE_DEPRECATE_WARNINGS /* LZ4_decompress_fast */ #include "lz4.h" #include <stdio.h> /* for printf() */ #include <stdlib.h> /* for exit() */ @@ -88,7 +89,6 @@ void run_screaming(const char *message, const int code) { printf("%s\n", message); exit(code); - return; } @@ -343,19 +343,19 @@ int main(int argc, char **argv) { printf("%s", separator); printf(header_format, "Source", "Function Benchmarked", "Total Seconds", "Iterations/sec", "ns/Iteration", "% of default"); printf("%s", separator); - printf(format, "Normal Text", "LZ4_compress_default()", (double)time_taken__default / BILLION, (int)(iterations / ((double)time_taken__default /BILLION)), time_taken__default / iterations, (double)time_taken__default * 100 / time_taken__default); - printf(format, "Normal Text", "LZ4_compress_fast()", (double)time_taken__fast / BILLION, (int)(iterations / ((double)time_taken__fast /BILLION)), time_taken__fast / iterations, (double)time_taken__fast * 100 / time_taken__default); - printf(format, "Normal Text", "LZ4_compress_fast_extState()", (double)time_taken__fast_extstate / BILLION, (int)(iterations / ((double)time_taken__fast_extstate /BILLION)), time_taken__fast_extstate / iterations, (double)time_taken__fast_extstate * 100 / time_taken__default); - //printf(format, "Normal Text", "LZ4_compress_generic()", (double)time_taken__generic / BILLION, (int)(iterations / ((double)time_taken__generic /BILLION)), time_taken__generic / iterations, (double)time_taken__generic * 100 / time_taken__default); - printf(format, "Normal Text", "LZ4_decompress_safe()", (double)time_taken__decomp_safe / BILLION, (int)(iterations / ((double)time_taken__decomp_safe /BILLION)), time_taken__decomp_safe / iterations, (double)time_taken__decomp_safe * 100 / time_taken__default); - printf(format, "Normal Text", "LZ4_decompress_fast()", (double)time_taken__decomp_fast / BILLION, (int)(iterations / ((double)time_taken__decomp_fast /BILLION)), time_taken__decomp_fast / iterations, (double)time_taken__decomp_fast * 100 / time_taken__default); + printf(format, "Normal Text", "LZ4_compress_default()", (double)time_taken__default / BILLION, (int)(iterations / ((double)time_taken__default /BILLION)), (int)time_taken__default / iterations, (double)time_taken__default * 100 / time_taken__default); + printf(format, "Normal Text", "LZ4_compress_fast()", (double)time_taken__fast / BILLION, (int)(iterations / ((double)time_taken__fast /BILLION)), (int)time_taken__fast / iterations, (double)time_taken__fast * 100 / time_taken__default); + printf(format, "Normal Text", "LZ4_compress_fast_extState()", (double)time_taken__fast_extstate / BILLION, (int)(iterations / ((double)time_taken__fast_extstate /BILLION)), (int)time_taken__fast_extstate / iterations, (double)time_taken__fast_extstate * 100 / time_taken__default); + //printf(format, "Normal Text", "LZ4_compress_generic()", (double)time_taken__generic / BILLION, (int)(iterations / ((double)time_taken__generic /BILLION)), (int)time_taken__generic / iterations, (double)time_taken__generic * 100 / time_taken__default); + printf(format, "Normal Text", "LZ4_decompress_safe()", (double)time_taken__decomp_safe / BILLION, (int)(iterations / ((double)time_taken__decomp_safe /BILLION)), (int)time_taken__decomp_safe / iterations, (double)time_taken__decomp_safe * 100 / time_taken__default); + printf(format, "Normal Text", "LZ4_decompress_fast()", (double)time_taken__decomp_fast / BILLION, (int)(iterations / ((double)time_taken__decomp_fast /BILLION)), (int)time_taken__decomp_fast / iterations, (double)time_taken__decomp_fast * 100 / time_taken__default); printf(header_format, "", "", "", "", "", ""); - printf(format, "Compressible", "LZ4_compress_default()", (double)time_taken_hc__default / BILLION, (int)(iterations / ((double)time_taken_hc__default /BILLION)), time_taken_hc__default / iterations, (double)time_taken_hc__default * 100 / time_taken_hc__default); - printf(format, "Compressible", "LZ4_compress_fast()", (double)time_taken_hc__fast / BILLION, (int)(iterations / ((double)time_taken_hc__fast /BILLION)), time_taken_hc__fast / iterations, (double)time_taken_hc__fast * 100 / time_taken_hc__default); - printf(format, "Compressible", "LZ4_compress_fast_extState()", (double)time_taken_hc__fast_extstate / BILLION, (int)(iterations / ((double)time_taken_hc__fast_extstate /BILLION)), time_taken_hc__fast_extstate / iterations, (double)time_taken_hc__fast_extstate * 100 / time_taken_hc__default); - //printf(format, "Compressible", "LZ4_compress_generic()", (double)time_taken_hc__generic / BILLION, (int)(iterations / ((double)time_taken_hc__generic /BILLION)), time_taken_hc__generic / iterations, (double)time_taken_hc__generic * 100 / time_taken_hc__default); - printf(format, "Compressible", "LZ4_decompress_safe()", (double)time_taken_hc__decomp_safe / BILLION, (int)(iterations / ((double)time_taken_hc__decomp_safe /BILLION)), time_taken_hc__decomp_safe / iterations, (double)time_taken_hc__decomp_safe * 100 / time_taken_hc__default); - printf(format, "Compressible", "LZ4_decompress_fast()", (double)time_taken_hc__decomp_fast / BILLION, (int)(iterations / ((double)time_taken_hc__decomp_fast /BILLION)), time_taken_hc__decomp_fast / iterations, (double)time_taken_hc__decomp_fast * 100 / time_taken_hc__default); + printf(format, "Compressible", "LZ4_compress_default()", (double)time_taken_hc__default / BILLION, (int)(iterations / ((double)time_taken_hc__default /BILLION)), (int)time_taken_hc__default / iterations, (double)time_taken_hc__default * 100 / time_taken_hc__default); + printf(format, "Compressible", "LZ4_compress_fast()", (double)time_taken_hc__fast / BILLION, (int)(iterations / ((double)time_taken_hc__fast /BILLION)), (int)time_taken_hc__fast / iterations, (double)time_taken_hc__fast * 100 / time_taken_hc__default); + printf(format, "Compressible", "LZ4_compress_fast_extState()", (double)time_taken_hc__fast_extstate / BILLION, (int)(iterations / ((double)time_taken_hc__fast_extstate /BILLION)), (int)time_taken_hc__fast_extstate / iterations, (double)time_taken_hc__fast_extstate * 100 / time_taken_hc__default); + //printf(format, "Compressible", "LZ4_compress_generic()", (double)time_taken_hc__generic / BILLION, (int)(iterations / ((double)time_taken_hc__generic /BILLION)), (int)time_taken_hc__generic / iterations, (double)time_taken_hc__generic * 100 / time_taken_hc__default); + printf(format, "Compressible", "LZ4_decompress_safe()", (double)time_taken_hc__decomp_safe / BILLION, (int)(iterations / ((double)time_taken_hc__decomp_safe /BILLION)), (int)time_taken_hc__decomp_safe / iterations, (double)time_taken_hc__decomp_safe * 100 / time_taken_hc__default); + printf(format, "Compressible", "LZ4_decompress_fast()", (double)time_taken_hc__decomp_fast / BILLION, (int)(iterations / ((double)time_taken_hc__decomp_fast /BILLION)), (int)time_taken_hc__decomp_fast / iterations, (double)time_taken_hc__decomp_fast * 100 / time_taken_hc__default); printf("%s", separator); printf("\n"); printf("All done, ran %d iterations per test.\n", iterations); diff --git a/examples/dictionaryRandomAccess.c b/examples/dictionaryRandomAccess.c index 291fd08..ecb3b2d 100644 --- a/examples/dictionaryRandomAccess.c +++ b/examples/dictionaryRandomAccess.c @@ -11,7 +11,7 @@ #include <stdlib.h> #include <string.h> -#define MIN(x, y) (x) < (y) ? (x) : (y) +#define MIN(x, y) ((x) < (y) ? (x) : (y)) enum { BLOCK_BYTES = 1024, /* 1 KiB of uncompressed data in a block */ @@ -63,7 +63,7 @@ void test_compress(FILE* outFp, FILE* inpFp, void *dict, int dictSize) int *offsetsEnd = offsets; - LZ4_resetStream(lz4Stream); + LZ4_initStream(lz4Stream, sizeof(*lz4Stream)); /* Write header magic */ write_bin(outFp, kTestMagic, sizeof(kTestMagic)); diff --git a/examples/frameCompress.c b/examples/frameCompress.c index a0c5d3d..aac4a3b 100644 --- a/examples/frameCompress.c +++ b/examples/frameCompress.c @@ -32,12 +32,12 @@ static void safe_fwrite(void* buf, size_t eltSize, size_t nbElt, FILE* f) { size_t const writtenSize = fwrite(buf, eltSize, nbElt, f); size_t const expectedSize = eltSize * nbElt; - assert(expectedSize / nbElt == eltSize); /* check overflow */ + if (nbElt>0) assert(expectedSize / nbElt == eltSize); /* check overflow */ if (writtenSize < expectedSize) { if (ferror(f)) /* note : ferror() must follow fwrite */ fprintf(stderr, "Write failed \n"); else - fprintf(stderr, "Short write \n"); + fprintf(stderr, "Write too short \n"); exit(1); } } @@ -70,11 +70,12 @@ compress_file_internal(FILE* f_in, FILE* f_out, /* write frame header */ { size_t const headerSize = LZ4F_compressBegin(ctx, outBuff, outCapacity, &kPrefs); if (LZ4F_isError(headerSize)) { - printf("Failed to start compression: error %zu\n", headerSize); + printf("Failed to start compression: error %u \n", (unsigned)headerSize); return result; } count_out = headerSize; - printf("Buffer size is %zu bytes, header size %zu bytes\n", outCapacity, headerSize); + printf("Buffer size is %u bytes, header size %u bytes \n", + (unsigned)outCapacity, (unsigned)headerSize); safe_fwrite(outBuff, 1, headerSize, f_out); } @@ -89,11 +90,11 @@ compress_file_internal(FILE* f_in, FILE* f_out, inBuff, readSize, NULL); if (LZ4F_isError(compressedSize)) { - printf("Compression failed: error %zu\n", compressedSize); + printf("Compression failed: error %u \n", (unsigned)compressedSize); return result; } - printf("Writing %zu bytes\n", compressedSize); + printf("Writing %u bytes\n", (unsigned)compressedSize); safe_fwrite(outBuff, 1, compressedSize, f_out); count_out += compressedSize; } @@ -103,11 +104,11 @@ compress_file_internal(FILE* f_in, FILE* f_out, outBuff, outCapacity, NULL); if (LZ4F_isError(compressedSize)) { - printf("Failed to end compression: error %zu\n", compressedSize); + printf("Failed to end compression: error %u \n", (unsigned)compressedSize); return result; } - printf("Writing %zu bytes\n", compressedSize); + printf("Writing %u bytes \n", (unsigned)compressedSize); safe_fwrite(outBuff, 1, compressedSize, f_out); count_out += compressedSize; } @@ -184,8 +185,8 @@ decompress_file_internal(FILE* f_in, FILE* f_out, while (ret != 0) { /* Load more input */ size_t readSize = firstChunk ? filled : fread(src, 1, srcCapacity, f_in); firstChunk=0; - const void* srcPtr = src + alreadyConsumed; alreadyConsumed=0; - const void* const srcEnd = srcPtr + readSize; + const void* srcPtr = (const char*)src + alreadyConsumed; alreadyConsumed=0; + const void* const srcEnd = (const char*)srcPtr + readSize; if (readSize == 0 || ferror(f_in)) { printf("Decompress: not enough input or error reading file\n"); return 1; @@ -198,7 +199,7 @@ decompress_file_internal(FILE* f_in, FILE* f_out, while (srcPtr < srcEnd && ret != 0) { /* Any data within dst has been flushed at this stage */ size_t dstSize = dstCapacity; - size_t srcSize = srcEnd - srcPtr; + size_t srcSize = (const char*)srcEnd - (const char*)srcPtr; ret = LZ4F_decompress(dctx, dst, &dstSize, srcPtr, &srcSize, /* LZ4F_decompressOptions_t */ NULL); if (LZ4F_isError(ret)) { printf("Decompression error: %s\n", LZ4F_getErrorName(ret)); @@ -207,7 +208,7 @@ decompress_file_internal(FILE* f_in, FILE* f_out, /* Flush output */ if (dstSize != 0) safe_fwrite(dst, 1, dstSize, f_out); /* Update input */ - srcPtr += srcSize; + srcPtr = (const char*)srcPtr + srcSize; } assert(srcPtr <= srcEnd); diff --git a/examples/simple_buffer.c b/examples/simple_buffer.c index 403d9e8..6afc62a 100644 --- a/examples/simple_buffer.c +++ b/examples/simple_buffer.c @@ -3,23 +3,22 @@ * Copyright : Kyle Harper * License : Follows same licensing as the lz4.c/lz4.h program at any given time. Currently, BSD 2. * Description: Example program to demonstrate the basic usage of the compress/decompress functions within lz4.c/lz4.h. - * The functions you'll likely want are LZ4_compress_default and LZ4_decompress_safe. Both of these are documented in - * the lz4.h header file; I recommend reading them. + * The functions you'll likely want are LZ4_compress_default and LZ4_decompress_safe. + * Both of these are documented in the lz4.h header file; I recommend reading them. */ -/* Includes, for Power! */ -#include "lz4.h" // This is all that is required to expose the prototypes for basic compression and decompression. +/* Dependencies */ #include <stdio.h> // For printf() #include <string.h> // For memcmp() #include <stdlib.h> // For exit() +#include "lz4.h" // This is all that is required to expose the prototypes for basic compression and decompression. /* - * Easy show-error-and-bail function. + * Simple show-error-and-bail function. */ -void run_screaming(const char *message, const int code) { - printf("%s\n", message); +void run_screaming(const char* message, const int code) { + printf("%s \n", message); exit(code); - return; } @@ -33,19 +32,19 @@ int main(void) { // 1) The return codes of LZ4_ functions are important. // Read lz4.h if you're unsure what a given code means. // 2) LZ4 uses char* pointers in all LZ4_ functions. - // This is baked into the API and probably not going to change. - // If your program uses pointers that are unsigned char*, void*, or otherwise different, - // you may need to do some casting or set the right -W compiler flags to ignore those warnings (e.g.: -Wno-pointer-sign). + // This is baked into the API and not going to change, for consistency. + // If your program uses different pointer types, + // you may need to do some casting or set the right -Wno compiler flags to ignore those warnings (e.g.: -Wno-pointer-sign). /* Compression */ // We'll store some text into a variable pointed to by *src to be compressed later. - const char* const src = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; + const char* const src = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor site amat."; // The compression function needs to know how many bytes exist. Since we're using a string, we can use strlen() + 1 (for \0). const int src_size = (int)(strlen(src) + 1); // 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(max_dst_size); + char* compressed_data = 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. @@ -53,21 +52,27 @@ int main(void) { // Save the return value for error checking. const int compressed_data_size = LZ4_compress_default(src, compressed_data, src_size, max_dst_size); // Check return_value to determine what happened. - if (compressed_data_size < 0) - run_screaming("A negative result from LZ4_compress_default indicates a failure trying to compress the data. See exit code (echo $?) for value returned.", compressed_data_size); - if (compressed_data_size == 0) - run_screaming("A result of 0 means compression worked, but was stopped because the destination buffer couldn't hold all the information.", 1); + if (compressed_data_size <= 0) + run_screaming("A 0 or negative result from LZ4_compress_default() indicates a failure trying to compress the data. ", 1); if (compressed_data_size > 0) - printf("We successfully compressed some data!\n"); + printf("We successfully compressed some data! Ratio: %.2f\n", + (float) compressed_data_size/src_size); // Not only does a positive return_value mean success, the value returned == the number of bytes required. // You can use this to realloc() *compress_data to free up memory, if desired. We'll do so just to demonstrate the concept. - compressed_data = (char *)realloc(compressed_data, compressed_data_size); + compressed_data = (char *)realloc(compressed_data, (size_t)compressed_data_size); if (compressed_data == NULL) run_screaming("Failed to re-alloc memory for compressed_data. Sad :(", 1); + /* Decompression */ - // Now that we've successfully compressed the information from *src to *compressed_data, let's do the opposite! We'll create a - // *new_src location of size src_size since we know that value. + // Now that we've successfully compressed the information from *src to *compressed_data, let's do the opposite! + // The decompression will need to know the compressed size, and an upper bound of the decompressed size. + // In this example, we just re-use this information from previous section, + // but in a real-world scenario, metadata must be transmitted to the decompression side. + // Each implementation is in charge of this part. Oftentimes, it adds some header of its own. + // 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); if (regen_buffer == NULL) run_screaming("Failed to allocate memory for *regen_buffer.", 1); @@ -78,17 +83,17 @@ int main(void) { free(compressed_data); /* no longer useful */ if (decompressed_size < 0) run_screaming("A negative result from LZ4_decompress_safe indicates a failure trying to decompress the data. See exit code (echo $?) for value returned.", decompressed_size); - if (decompressed_size == 0) - run_screaming("I'm not sure this function can ever return 0. Documentation in lz4.h doesn't indicate so.", 1); - if (decompressed_size > 0) + if (decompressed_size >= 0) printf("We successfully decompressed some data!\n"); // Not only does a positive return value mean success, // value returned == number of bytes regenerated from compressed_data stream. + if (decompressed_size != src_size) + run_screaming("Decompressed data is different from original! \n", 1); /* Validation */ // We should be able to compare our original *src with our *new_src and be byte-for-byte identical. if (memcmp(src, regen_buffer, src_size) != 0) run_screaming("Validation failed. *src and *new_src are not identical.", 1); - printf("Validation done. The string we ended up with is:\n%s\n", regen_buffer); + printf("Validation done. The string we ended up with is:\n%s\n", regen_buffer); return 0; } diff --git a/examples/streaming_api_basics.md b/examples/streaming_api_basics.md index 90065e4..1ccc6e3 100644 --- a/examples/streaming_api_basics.md +++ b/examples/streaming_api_basics.md @@ -10,7 +10,7 @@ LZ4 has the following API sets : 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. - - "Streaming" API : This is designed for complex thing. + - "Streaming" API : This is designed for complex things. For example, compress huge stream data in restricted memory environment. Basically, you should use "Auto Framing" API. @@ -19,13 +19,13 @@ But if you want to write advanced application, it's time to use Block or Streami ## What is difference between Block and Streaming API ? -Block API (de)compresses single contiguous memory block. -In other words, LZ4 library find redundancy from single contiguous memory block. -Streaming API does same thing but (de)compress multiple adjacent contiguous memory block. +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. The following figure shows difference between API and block sizes. -In these figures, original data is splitted to 4KiBytes contiguous chunks. +In these figures, the original data is split into 4KiBytes contiguous chunks. ``` Original Data @@ -81,7 +81,7 @@ This dependency improves compression ratio. ## Restriction of Streaming API -For the efficiency, Streaming API doesn't keep mirror copy of dependent (de)compressed memory. +For efficiency, Streaming API doesn't keep a mirror copy of dependent (de)compressed memory. This means users should keep these dependent (de)compressed memory explicitly. Usually, "Dependent memory" is previous adjacent contiguous memory up to 64KiBytes. LZ4 will not access further memories. |