mirror of
https://github.com/facebook/zstd.git
synced 2025-12-21 00:04:29 -05:00
spec: clarify how bitstream exactly needs to be reversed for reading
This commit is contained in:
parent
6fb4d675c6
commit
35ad602c26
@ -1049,15 +1049,23 @@ by reading the required `Number_of_Bits`, and adding the specified `Baseline`.
|
|||||||
|
|
||||||
#### Bitstream
|
#### Bitstream
|
||||||
|
|
||||||
All sequences are stored in a single bitstream, read _backward_.
|
FSE bitstreams are read in reverse direction than written. In zstd,
|
||||||
It is therefore necessary to know the bitstream size,
|
the compressor writes bits forward into a block and the decompressor
|
||||||
which is deducted from compressed block size.
|
must read the bitstream _backwards_.
|
||||||
|
|
||||||
The last useful bit of the stream is followed by an end-bit-flag.
|
To find the start of the bitstream it is therefore necessary to
|
||||||
Highest bit of last byte is this flag.
|
know the offset of the last byte of the block which can be found
|
||||||
It does not belong to the useful part of the bitstream.
|
by counting `Block_Size` bytes after the block header.
|
||||||
Therefore, last byte has 0-7 useful bits.
|
|
||||||
Note that it also means that last byte cannot be `0`.
|
After writing the last bit containing information, the compressor
|
||||||
|
writes a single `1`-bit and then fills the byte with 0-7 `0` bits of
|
||||||
|
padding. The last byte of the compressed bitstream cannot be `0` for
|
||||||
|
that reason.
|
||||||
|
|
||||||
|
When decompressing, the last byte containing the padding is the first
|
||||||
|
byte to read. The decompressor needs to skip 0-7 initial `0`-bits and
|
||||||
|
the first `1`-bit it occurs. Afterwards, the useful part of the bitstream
|
||||||
|
begins.
|
||||||
|
|
||||||
##### Starting states
|
##### Starting states
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user