git subrepo pull (merge) --force deps/libchdr
[pcsx_rearmed.git] / deps / libchdr / deps / zstd-1.5.5 / contrib / seekable_format / README.md
CommitLineData
648db22b 1# Zstandard Seekable Format
2
3The seekable format splits compressed data into a series of independent "frames",
4each compressed individually,
5so that decompression of a section in the middle of an archive
6only requires zstd to decompress at most a frame's worth of extra data,
7instead of the entire archive.
8
9The frames are appended, so that the decompression of the entire payload
10still regenerates the original content, using any compliant zstd decoder.
11
12On top of that, the seekable format generates a jump table,
13which makes it possible to jump directly to the position of the relevant frame
14when requesting only a segment of the data.
15The jump table is simply ignored by zstd decoders unaware of the seekable format.
16
17The format is delivered with an API to create seekable archives
18and to retrieve arbitrary segments inside the archive.
19
20### Maximum Frame Size parameter
21
22When creating a seekable archive, the main parameter is the maximum frame size.
23
24At compression time, user can manually select the boundaries between segments,
25but they don't have to: long segments will be automatically split
26when larger than selected maximum frame size.
27
28Small frame sizes reduce decompression cost when requesting small segments,
29because the decoder will nonetheless have to decompress an entire frame
30to recover just a single byte from it.
31
32A good rule of thumb is to select a maximum frame size roughly equivalent
33to the access pattern when it's known.
34For example, if the application tends to request 4KB blocks,
35then it's a good idea to set a maximum frame size in the vicinity of 4 KB.
36
37But small frame sizes also reduce compression ratio,
38and increase the cost for the jump table,
39so there is a balance to find.
40
41In general, try to avoid really tiny frame sizes (<1 KB),
42which would have a large negative impact on compression ratio.