summaryrefslogtreecommitdiffstats
path: root/examples/blockStreaming_doubleBuffer.md
diff options
context:
space:
mode:
authorYann Collet <yann.collet.73@gmail.com>2015-03-25 12:31:06 (GMT)
committerYann Collet <yann.collet.73@gmail.com>2015-03-25 12:31:06 (GMT)
commite652285556c421901fc1bcc9a571c3ddba767181 (patch)
tree150a8c0be529c115c2c3099a7190a4bf3fbfd2e2 /examples/blockStreaming_doubleBuffer.md
parent80e71c6e8b0cbcd3b9976ded45cef1474a34b40c (diff)
parent2af52a90b3759e589d608782a987d2b3d73abefb (diff)
downloadlz4-e652285556c421901fc1bcc9a571c3ddba767181.zip
lz4-e652285556c421901fc1bcc9a571c3ddba767181.tar.gz
lz4-e652285556c421901fc1bcc9a571c3ddba767181.tar.bz2
Merge pull request #63 from t-mat/comment-on-example-directory
Comment on example directory
Diffstat (limited to 'examples/blockStreaming_doubleBuffer.md')
-rw-r--r--examples/blockStreaming_doubleBuffer.md99
1 files changed, 99 insertions, 0 deletions
diff --git a/examples/blockStreaming_doubleBuffer.md b/examples/blockStreaming_doubleBuffer.md
new file mode 100644
index 0000000..cd295df
--- /dev/null
+++ b/examples/blockStreaming_doubleBuffer.md
@@ -0,0 +1,99 @@
+# LZ4 Streaming API Example : Double Buffer
+
+`blockStreaming_doubleBuffer.c` is LZ4 Straming API example which implements double buffer (de)compression.
+
+Please note :
+
+ - Firstly, read "LZ4 Streaming API Basics".
+ - This is relatively advanced application example.
+ - Output file is not compatible with lz4frame and platform dependent.
+
+
+## What's the point of this example ?
+
+ - Handle huge file in small amount of memory
+ - Always better compression ratio than Block API
+ - Uniform block size
+
+
+## How the compression works
+
+First of all, allocate "Double Buffer" for input and LZ4 compressed data buffer for output.
+Double buffer has two pages, "first" page (Page#1) and "second" page (Page#2).
+
+```
+ Double Buffer
+
+ Page#1 Page#2
+ +---------+---------+
+ | Block#1 | |
+ +----+----+---------+
+ |
+ v
+ {Out#1}
+
+
+ Prefix Dependency
+ +---------+
+ | |
+ v |
+ +---------+----+----+
+ | Block#1 | Block#2 |
+ +---------+----+----+
+ |
+ v
+ {Out#2}
+
+
+ External Dictionary Mode
+ +---------+
+ | |
+ | v
+ +----+----+---------+
+ | Block#3 | Block#2 |
+ +----+----+---------+
+ |
+ v
+ {Out#3}
+
+
+ Prefix Dependency
+ +---------+
+ | |
+ v |
+ +---------+----+----+
+ | Block#3 | Block#4 |
+ +---------+----+----+
+ |
+ v
+ {Out#4}
+```
+
+Next, read first block to double buffer's first page. And compress it by `LZ4_compress_continue()`.
+For the first time, LZ4 doesn't know any previous dependencies,
+so it just compress the line without dependencies and generates compressed block {Out#1} to LZ4 compressed data buffer.
+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 dependency is called "Prefix mode".
+
+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".
+
+Continue these procedure to the end of the file.
+
+
+## How the decompression works
+
+Decompression will do reverse order.
+
+ - Read first compressed block.
+ - Decompress it to the first page and write that page to the file.
+ - Read second compressed block.
+ - Decompress it to the second page and write that page to the file.
+ - Read third compressed block.
+ - Decompress it to the *first* page and write that page to the file.
+
+Continue these procedure to the end of the compressed file.