blob: 7816d1cb998cbd7758bee61f0947fd92a46a7fdd [file] [log] [blame] [view]
Yann Collet5cc18822016-07-03 19:03:13 +02001Zstandard Compression Format
2============================
Yann Collet2fa99042016-07-01 20:55:28 +02003
4### Notices
5
6Copyright (c) 2016 Yann Collet
7
8Permission is granted to copy and distribute this document
9for any purpose and without charge,
10including translations into other languages
11and incorporation into compilations,
12provided that the copyright notice and this notice are preserved,
13and that any substantive changes or deletions from the original
14are clearly marked.
15Distribution of this document is unlimited.
16
17### Version
18
Yann Colletd916c902016-07-04 00:42:58 +0200190.0.2 (July 2016 - Work in progress - unfinished)
Yann Collet2fa99042016-07-01 20:55:28 +020020
21
22Introduction
23------------
24
25The purpose of this document is to define a lossless compressed data format,
26that is independent of CPU type, operating system,
27file system and character set, suitable for
28File compression, Pipe and streaming compression
29using the [Zstandard algorithm](http://www.zstandard.org).
30
31The data can be produced or consumed,
32even for an arbitrarily long sequentially presented input data stream,
33using only an a priori bounded amount of intermediate storage,
34and hence can be used in data communications.
35The format uses the Zstandard compression method,
36and optional [xxHash-64 checksum method](http://www.xxhash.org),
37for detection of data corruption.
38
39The data format defined by this specification
40does not attempt to allow random access to compressed data.
41
42This specification is intended for use by implementers of software
43to compress data into Zstandard format and/or decompress data from Zstandard format.
44The text of the specification assumes a basic background in programming
45at the level of bits and other primitive data representations.
46
47Unless otherwise indicated below,
48a compliant compressor must produce data sets
49that conform to the specifications presented here.
50It doesnt need to support all options though.
51
52A compliant decompressor must be able to decompress
53at least one working set of parameters
54that conforms to the specifications presented here.
55It may also ignore informative fields, such as checksum.
56Whenever it does not support a parameter defined in the compressed stream,
57it must produce a non-ambiguous error code and associated error message
58explaining which parameter is unsupported.
59
60
61Definitions
62-----------
63A content compressed by Zstandard is transformed into a Zstandard __frame__.
64Multiple frames can be appended into a single file or stream.
65A frame is totally independent, has a defined beginning and end,
66and a set of parameters which tells the decoder how to decompress it.
67
68A frame encapsulates one or multiple __blocks__.
69Each block can be compressed or not,
70and has a guaranteed maximum content size, which depends on frame parameters.
71Unlike frames, each block depends on previous blocks for proper decoding.
72However, each block can be decompressed without waiting for its successor,
73allowing streaming operations.
74
75
76General Structure of Zstandard Frame format
77-------------------------------------------
78
79| MagicNb | F. Header | Block | (More blocks) | EndMark |
80|:-------:|:----------:| ----- | ------------- | ------- |
81| 4 bytes | 2-14 bytes | | | 3 bytes |
82
83__Magic Number__
84
854 Bytes, Little endian format.
86Value : 0xFD2FB527
87
88__Frame Header__
89
902 to 14 Bytes, to be detailed in the next part.
91
92__Data Blocks__
93
94To be detailed later on.
95Thats where compressed data is stored.
96
97__EndMark__
98
99The flow of blocks ends when the last block header brings an _end signal_ .
100This last block header may optionally host a __Content Checksum__ .
101
102__Content Checksum__
103
104Content Checksum verify that frame content has been regenrated correctly.
105The content checksum is the result
106of [xxh64() hash function](https://www.xxHash.com)
107digesting the original (decoded) data as input, and a seed of zero.
108Bits from 11 to 32 (included) are extracted to form a 22 bits checksum
109stored into the last block header.
110```
111contentChecksum = (XXH64(content, size, 0) >> 11) & (1<<22)-1);
112```
113Content checksum is only present when its associated flag
114is set in the frame descriptor.
115Its usage is optional.
116
117__Frame Concatenation__
118
119In some circumstances, it may be required to append multiple frames,
120for example in order to add new data to an existing compressed file
121without re-framing it.
122
123In such case, each frame brings its own set of descriptor flags.
124Each frame is considered independent.
125The only relation between frames is their sequential order.
126
127The ability to decode multiple concatenated frames
128within a single stream or file is left outside of this specification.
129As an example, the reference `zstd` command line utility is able
130to decode all concatenated frames in their sequential order,
131delivering the final decompressed result as if it was a single content.
132
133
134Frame Header
135-------------
136
137| FHD | (WD) | (Content Size) | (dictID) |
138| ------- | --------- |:--------------:| --------- |
139| 1 byte | 0-1 byte | 0 - 8 bytes | 0-4 bytes |
140
141Frame header has a variable size, which uses a minimum of 2 bytes,
142and up to 14 bytes depending on optional parameters.
143
144__FHD byte__ (Frame Header Descriptor)
145
146The first Header's byte is called the Frame Header Descriptor.
147It tells which other fields are present.
148Decoding this byte is enough to get the full size of the Frame Header.
149
150| BitNb | 7-6 | 5 | 4 | 3 | 2 | 1-0 |
151| ------- | ------ | ------- | ------ | -------- | -------- | -------- |
152|FieldName| FCSize | Segment | Unused | Reserved | Checksum | dictID |
153
154In this table, bit 7 is highest bit, while bit 0 is lowest.
155
156__Frame Content Size flag__
157
158This is a 2-bits flag (`= FHD >> 6`),
159specifying if decompressed data size is provided within the header.
160
161| Value | 0 | 1 | 2 | 3 |
162| ------- | --- | --- | --- | --- |
163|FieldSize| 0-1 | 2 | 4 | 8 |
164
165Value 0 has a double meaning :
166it either means `0` (size not provided) _if_ the `WD` byte is present,
167or it means `1` byte (size <= 255 bytes).
168
169__Single Segment__
170
171If this flag is set,
172data shall be regenerated within a single continuous memory segment.
173In which case, `WD` byte __is not present__,
174but `Frame Content Size` field necessarily is.
175
176As a consequence, the decoder must allocate a memory segment
177of size `>= Frame Content Size`.
178
179In order to preserve the decoder from unreasonable memory requirement,
180a decoder can refuse a compressed frame
181which requests a memory size beyond decoder's authorized range.
182
183For broader compatibility, decoders are recommended to support
184memory sizes of 8 MB at least.
185However, this is merely a recommendation,
186and each decoder is free to support higher or lower limits,
187depending on local limitations.
188
189__Unused bit__
190
191The value of this bit is unimportant
192and not interpreted by a decoder compliant with this specification version.
193It may be used in a future revision,
194to signal a property which is not required to properly decode the frame.
195
196__Reserved bit__
197
198This bit is reserved for some future feature.
199Its value _must be zero_.
200A decoder compliant with this specification version must ensure it is not set.
201This bit may be used in a future revision,
202to signal a feature that must be interpreted in order to decode the frame.
203
204__Content checksum flag__
205
206If this flag is set, a content checksum will be present into the EndMark.
207The checksum is a 22 bits value extracted from the XXH64() of data.
208See __Content Checksum__ .
209
210__Dictionary ID flag__
211
212This is a 2-bits flag (`= FHD & 3`),
213telling if a dictionary ID is provided within the header
214
215| Value | 0 | 1 | 2 | 3 |
216| ------- | --- | --- | --- | --- |
217|FieldSize| 0 | 1 | 2 | 4 |
218
219__WD byte__ (Window Descriptor)
220
221Provides guarantees on maximum back-reference distance
222that will be present within compressed data.
223This information is useful for decoders to allocate enough memory.
224
225| BitNb | 7-3 | 0-2 |
226| --------- | -------- | -------- |
227| FieldName | Exponent | Mantissa |
228
229Maximum distance is given by the following formulae :
230```
231windowLog = 10 + Exponent;
232windowBase = 1 << windowLog;
233windowAdd = (windowBase / 8) * Mantissa;
234windowSize = windowBase + windowAdd;
235```
236The minimum window size is 1 KB.
237The maximum size is (15*(2^38))-1 bytes, which is almost 1.875 TB.
238
239To properly decode compressed data,
240a decoder will need to allocate a buffer of at least `windowSize` bytes.
241
242Note that `WD` byte is optional. It's not present in `single segment` mode.
243In which case, the maximum back-reference distance is the content size itself,
244which can be any value from 1 to 2^64-1 bytes (16 EB).
245
246In order to preserve decoder from unreasonable memory requirements,
247a decoder can refuse a compressed frame
248which requests a memory size beyond decoder's authorized range.
249
250For better interoperability,
251decoders are recommended to be compatible with window sizes of 8 MB.
252Encoders are recommended to not request more than 8 MB.
253It's merely a recommendation though,
254decoders are free to support larger or lower limits,
255depending on local limitations.
256
257__Frame Content Size__
258
259This is the original (uncompressed) size.
260This information is optional, and only present if associated flag is set.
261Content size is provided using 1, 2, 4 or 8 Bytes.
262Format is Little endian.
263
264| Field Size | Range |
265| ---------- | ---------- |
266| 0 | 0 |
267| 1 | 0 - 255 |
268| 2 | 256 - 65791|
269| 4 | 0 - 2^32-1 |
270| 8 | 0 - 2^64-1 |
271
272When field size is 1, 4 or 8 bytes, the value is read directly.
273When field size is 2, _an offset of 256 is added_.
274It's allowed to represent a small size (ex: `18`) using the 8-bytes variant.
275A size of `0` means `content size is unknown`.
276In which case, the `WD` byte will necessarily be present,
277and becomes the only hint to determine memory allocation.
278
279In order to preserve decoder from unreasonable memory requirement,
280a decoder can refuse a compressed frame
281which requests a memory size beyond decoder's authorized range.
282
283__Dictionary ID__
284
285This is a variable size field, which contains a single ID.
286It checks if the correct dictionary is used for decoding.
287Note that this field is optional. If it's not present,
288it's up to the caller to make sure it uses the correct dictionary.
289
290Field size depends on __Dictionary ID flag__.
2911 byte can represent an ID 0-255.
2922 bytes can represent an ID 0-65535.
2934 bytes can represent an ID 0-(2^32-1).
294
295It's allowed to represent a small ID (for example `13`)
296with a large 4-bytes dictionary ID, losing some efficiency in the process.
297
298
299Data Blocks
300-----------
301
302| B. Header | data |
303|:---------:| ------ |
304| 3 bytes | |
305
306
307__Block Header__
308
309This field uses 3-bytes, format is __big-endian__.
310
311The 2 highest bits represent the `block type`,
312while the remaining 22 bits represent the (compressed) block size.
313
314There are 4 block types :
315
316| Value | 0 | 1 | 2 | 3 |
317| ---------- | ---------- | --- | --- | ------- |
318| Block Type | Compressed | Raw | RLE | EndMark |
319
320- Compressed : this is a Zstandard compressed block,
321 detailed in a later part of this specification.
322 "block size" is the compressed size.
323 Decompressed size is unknown,
324 but its maximum possible value is guaranteed (see below)
325- Raw : this is an uncompressed block.
326 "block size" is the number of bytes to read and copy.
327- RLE : this is a single byte, repeated N times.
328 In which case, "block size" is the size to regenerate,
329 while the "compressed" block is just 1 byte (the byte to repeat).
330- EndMark : this is not a block. Signal the end of the frame.
331 The rest of the field may be optionally filled by a checksum
332 (see frame checksum).
333
334Block sizes must respect a few rules :
335- In compressed mode, compressed size if always strictly `< contentSize`.
336- Block decompressed size is necessarily <= maximum back-reference distance .
337- Block decompressed size is necessarily <= 128 KB
338
339
340__Data__
341
342Where the actual data to decode stands.
343It might be compressed or not, depending on previous field indications.
344A data block is not necessarily "full" :
345since an arbitrary flush may happen anytime,
346block content can be any size, up to Block Maximum Size.
347Block Maximum Size is the smallest of :
348- Max back-reference distance
349- 128 KB
350
351
352Skippable Frames
353----------------
354
355| Magic Number | Frame Size | User Data |
356|:------------:|:----------:| --------- |
357| 4 bytes | 4 bytes | |
358
359Skippable frames allow the insertion of user-defined data
360into a flow of concatenated frames.
361Its design is pretty straightforward,
362with the sole objective to allow the decoder to quickly skip
363over user-defined data and continue decoding.
364
365Skippable frames defined in this specification are compatible with LZ4 ones.
366
367
368__Magic Number__ :
369
3704 Bytes, Little endian format.
371Value : 0x184D2A5X, which means any value from 0x184D2A50 to 0x184D2A5F.
372All 16 values are valid to identify a skippable frame.
373
374__Frame Size__ :
375
376This is the size, in bytes, of the following User Data
377(without including the magic number nor the size field itself).
3784 Bytes, Little endian format, unsigned 32-bits.
379This means User Data cant be bigger than (2^32-1) Bytes.
380
381__User Data__ :
382
383User Data can be anything. Data will just be skipped by the decoder.
384
385
386Compressed block format
387-----------------------
388This specification details the content of a _compressed block_.
389A compressed block has a size, which must be known in order to decode it.
390It also has a guaranteed maximum regenerated size,
391in order to properly allocate destination buffer.
392See "Frame format" for more details.
393
394A compressed block consists of 2 sections :
395- Literals section
396- Sequences section
397
Yann Collet698cb632016-07-03 18:49:35 +0200398### Prerequisite
399For proper decoding, a compressed block requires access to following elements :
400- Previous decoded blocks, up to a distance of `windowSize`,
401 or all previous blocks in the same frame "single segment" mode.
402- List of "recent offsets" from previous compressed block.
403
404
Yann Collet2fa99042016-07-01 20:55:28 +0200405### Compressed Literals
406
407Literals are compressed using order-0 huffman compression.
408During sequence phase, literals will be entangled with match copy operations.
409All literals are regrouped in the first part of the block.
410They can be decoded first, and then copied during sequence operations,
411or they can be decoded on the flow, as needed by sequences.
412
413| Header | (Tree Description) | Stream1 | (Stream2) | (Stream3) | (Stream4) |
414| ------ | ------------------ | ------- | --------- | --------- | --------- |
415
416Literals can be compressed, or uncompressed.
417When compressed, an optional tree description can be present,
418followed by 1 or 4 streams.
419
420#### Block Literal Header
421
422Header is in charge of describing precisely how literals are packed.
423It's a byte-aligned variable-size bitfield, ranging from 1 to 5 bytes,
424using big-endian convention.
425
426| BlockType | sizes format | (compressed size) | regenerated size |
427| --------- | ------------ | ----------------- | ---------------- |
428| 2 bits | 1 - 2 bits | 0 - 18 bits | 5 - 20 bits |
429
430__Block Type__ :
431
432This is a 2-bits field, describing 4 different block types :
433
434| Value | 0 | 1 | 2 | 3 |
435| ---------- | ---------- | ------ | --- | ------- |
436| Block Type | Compressed | Repeat | Raw | RLE |
437
438- Compressed : This is a standard huffman-compressed block,
439 starting with a huffman tree description.
440 See details below.
441- Repeat Stats : This is a huffman-compressed block,
442 using huffman tree from previous huffman-compressed block.
443 Huffman tree description will be skipped.
444 Compressed stream is equivalent to "compressed" block type.
445- Raw : Literals are stored uncompressed.
446- RLE : Literals consist of a single byte value repeated N times.
447
448__Sizes format__ :
449
450Sizes format are divided into 2 families :
451
452- For compressed block, it requires to decode both the compressed size
453 and the decompressed size. It will also decode the number of streams.
454- For Raw or RLE blocks, it's enough to decode the size to regenerate.
455
456For values spanning several bytes, convention is Big-endian.
457
458__Sizes format for Raw or RLE block__ :
459
460- Value : 0x : Regenerated size uses 5 bits (0-31).
461 Total literal header size is 1 byte.
462 `size = h[0] & 31;`
463- Value : 10 : Regenerated size uses 12 bits (0-4095).
464 Total literal header size is 2 bytes.
465 `size = ((h[0] & 15) << 8) + h[1];`
466- Value : 11 : Regenerated size uses 20 bits (0-1048575).
Yann Colletd916c902016-07-04 00:42:58 +0200467 Total literal header size is 3 bytes.
Yann Collet2fa99042016-07-01 20:55:28 +0200468 `size = ((h[0] & 15) << 16) + (h[1]<<8) + h[2];`
469
470Note : it's allowed to represent a short value (ex : `13`)
471using a long format, accepting the reduced compacity.
472
473__Sizes format for Compressed Block__ :
474
475Note : also applicable to "repeat-stats" blocks.
476- Value : 00 : 4 streams
477 Compressed and regenerated sizes use 10 bits (0-1023)
478 Total literal header size is 3 bytes
479- Value : 01 : _Single stream_
480 Compressed and regenerated sizes use 10 bits (0-1023)
481 Total literal header size is 3 bytes
482- Value : 10 : 4 streams
483 Compressed and regenerated sizes use 14 bits (0-16383)
484 Total literal header size is 4 bytes
485- Value : 10 : 4 streams
486 Compressed and regenerated sizes use 18 bits (0-262143)
487 Total literal header size is 5 bytes
488
Yann Collet698cb632016-07-03 18:49:35 +0200489Compressed and regenerated size fields follow big endian convention.
490
491#### Huffman Tree description
492
493This section is only present when block type is _compressed_ (`0`).
494It describes the different leaf nodes of the huffman tree,
495and their relative weights.
496
497##### Representation
498
499All byte values from zero (included) to last present one (excluded)
500are represented by `weight` values, from 0 to `maxBits`.
501Transformation from `weight` to `nbBits` follows this formulae :
502`nbBits = weight ? maxBits + 1 - weight : 0;` .
503The last symbol's weight is deduced from previously decoded ones,
504by completing to the nearest power of 2.
505This power of 2 gives `maxBits`, the depth of the current tree.
506
507__Example__ :
508Let's presume the following huffman tree must be described :
509
Yann Colletd916c902016-07-04 00:42:58 +0200510| literal | 0 | 1 | 2 | 3 | 4 | 5 |
511| ------- | --- | --- | --- | --- | --- | --- |
512| nbBits | 1 | 2 | 3 | 0 | 4 | 4 |
Yann Collet698cb632016-07-03 18:49:35 +0200513
514The tree depth is 4, since its smallest element uses 4 bits.
515Value `5` will not be listed, nor will values above `5`.
516Values from `0` to `4` will be listed using `weight` instead of `nbBits`.
517Weight formula is : `weight = nbBits ? maxBits + 1 - nbBits : 0;`
518It gives the following serie of weights :
519
Yann Colletd916c902016-07-04 00:42:58 +0200520| weights | 4 | 3 | 2 | 0 | 1 |
521| ------- | --- | --- | --- | --- | --- |
522| literal | 0 | 1 | 2 | 3 | 4 |
Yann Collet698cb632016-07-03 18:49:35 +0200523
524The decoder will do the inverse operation :
Yann Colletd916c902016-07-04 00:42:58 +0200525having collected weights of literals from `0` to `4`,
526it knows the last literal, `5`, is present with a non-zero weight.
Yann Collet698cb632016-07-03 18:49:35 +0200527The weight of `5` can be deduced by joining to the nearest power of 2.
528Sum of 2^(weight-1) (excluding 0) is :
Yann Colletd916c902016-07-04 00:42:58 +0200529`8 + 4 + 2 + 0 + 1 = 15`
Yann Collet698cb632016-07-03 18:49:35 +0200530Nearest power of 2 is 16.
531Therefore, `maxBits = 4` and `weight[5] = 1`.
Yann Collet698cb632016-07-03 18:49:35 +0200532
533##### Huffman Tree header
534
535This is a single byte value (0-255), which tells how to decode the tree.
536
537- if headerByte >= 242 : this is one of 14 pre-defined weight distributions :
538 + 242 : 1x1 (+ 1x1)
539 + 243 : 2x1 (+ 1x2)
540 + 244 : 3x1 (+ 1x1)
541 + 245 : 4x1 (+ 1x4)
542 + 246 : 7x1 (+ 1x1)
543 + 247 : 8x1 (+ 1x8)
544 + 248 : 15x1 (+ 1x1)
545 + 249 : 16x1 (+ 1x16)
546 + 250 : 31x1 (+ 1x1)
547 + 251 : 32x1 (+ 1x32)
548 + 252 : 63x1 (+ 1x1)
549 + 253 : 64x1 (+ 1x64)
550 + 254 :127x1 (+ 1x1)
551 + 255 :128x1 (+ 1x128)
552
553- if headerByte >= 128 : this is a direct representation,
554 where each weight is written directly as a 4 bits field (0-15).
555 The full representation occupies (nbSymbols+1/2) bytes,
556 meaning it uses a last full byte even if nbSymbols is odd.
557 `nbSymbols = headerByte - 127;`
558
559- if headerByte < 128 :
560 the serie of weights is compressed by FSE.
561 The length of the compressed serie is `headerByte` (0-127).
562
563##### FSE (Finite State Entropy) compression of huffman weights
564
565The serie of weights is compressed using standard FSE compression.
566It's a single bitstream with 2 interleaved states,
567using a single distribution table.
568
569To decode an FSE bitstream, it is necessary to know its compressed size.
570Compressed size is provided by `headerByte`.
571It's also necessary to know its maximum decompressed size.
572In this case, it's `255`, since literal values range from `0` to `255`,
573and the last symbol value is not represented.
574
575An FSE bitstream starts by a header, describing probabilities distribution.
576Result will create a Decoding Table.
577It is necessary to know the maximum accuracy of distribution
578to properly allocate space for the Table.
579For a list of huffman weights, this maximum is 8 bits.
580
581FSE header and bitstreams are described in a separated chapter.
582
583##### Conversion from weights to huffman prefix codes
584
Yann Colletd916c902016-07-04 00:42:58 +0200585All present symbols shall now have a `weight` value.
586A `weight` directly represent a `range` of prefix codes,
587following the formulae : `range = weight ? 1 << (weight-1) : 0 ;`
588Symbols are sorted by weight.
589Within same weight, symbols keep natural order.
590Starting from lowest weight,
591symbols are being allocated to a range of prefix codes.
592Symbols with a weight of zero are not present.
593
594It can then proceed to transform weights into nbBits :
595`nbBits = nbBits ? maxBits + 1 - weight : 0;` .
596
597
598__Example__ :
599Let's presume the following huffman tree has been decoded :
600
601| Literal | 0 | 1 | 2 | 3 | 4 | 5 |
602| ------- | --- | --- | --- | --- | --- | --- |
603| weight | 4 | 3 | 2 | 0 | 1 | 1 |
604
605Sorted by weight and then natural order,
606it gives the following distribution :
607
608| Literal | 3 | 4 | 5 | 2 | 1 | 0 |
609| ------------ | --- | --- | --- | --- | --- | ---- |
610| weight | 0 | 1 | 1 | 2 | 3 | 4 |
611| range | 0 | 1 | 1 | 2 | 4 | 8 |
612| prefix codes | N/A | 0 | 1 | 2-3 | 4-7 | 8-15 |
613| nb bits | 0 | 4 | 4 | 3 | 2 | 1 |
614
615
616
617#### Literals bitstreams
618
619##### Bitstreams sizes
620
621As seen in a previous paragraph,
622there are 2 flavors of huffman-compressed literals :
623single stream, and 4-streams.
624
6254-streams is useful for CPU with multiple execution units and OoO operations.
626Since each stream can be decoded independently,
627it's possible to decode them up to 4x faster than a single stream,
628presuming the CPU has enough parallelism available.
629
630For single stream, header provides both the compressed and regenerated size.
631For 4-streams though,
632header only provides compressed and regenerated size of all 4 streams combined.
633
634In order to properly decode the 4 streams,
635it's necessary to know the compressed and regenerated size of each stream.
636
637Regenerated size is easiest :
638each stream has a size of `(totalSize+3)/4`,
639except the last one, which is up to 3 bytes smaller, to reach totalSize.
640
641Compressed size must be provided explicitly : in the 4-streams variant,
642bitstream is preceded by 3 unsigned short values using Little Endian convention.
643Each value represent the compressed size of one stream, in order.
644The last stream size is deducted from total compressed size
645and from already known stream sizes :
646`stream4CSize = totalCSize - 6 - stream1CSize - stream2CSize - stream3CSize;`
647
648##### Bitstreams reading
649
650Each bitstream must be read _backward_,
651that is starting from the end down to the beginning.
652Therefore it's necessary to know the size of each bitstream.
653
654It's also necessary to know exactly which _bit_ is the latest.
655This is detected by a final bit flag :
656the highest bit of latest byte is a final-bit-flag.
657Consequently, a last byte of `0` is not possible.
658And the final-bit-flag itself is not part of the useful bitstream.
659Hence, the last byte contain between 0 and 7 useful bits.
660
661Starting from the end,
662it's possible to read the bitstream in a little-endian fashion,
663keeping track of already used bits.
664
665Extracting `maxBits`,
666it's then possible to compare extracted value to the prefix codes table,
667determining the symbol to decode and number of bits to discard.
668
669The process continues up to reading the required number of symbols per stream.
670If a bitstream is not entirely and exactly consumed,
671hence reaching exactly its beginning position with all bits consumed,
672the decoding process is considered faulty.
673
Yann Collet698cb632016-07-03 18:49:35 +0200674
Yann Collet2fa99042016-07-01 20:55:28 +0200675
676
677Version changes
678---------------