xref: /aosp_15_r20/external/zstd/doc/educational_decoder/README.md (revision 01826a4963a0d8a59bc3812d29bdf0fb76416722)
1*01826a49SYabin CuiEducational Decoder
2*01826a49SYabin Cui===================
3*01826a49SYabin Cui
4*01826a49SYabin Cui`zstd_decompress.c` is a self-contained implementation in C99 of a decoder,
5*01826a49SYabin Cuiaccording to the [Zstandard format specification].
6*01826a49SYabin CuiWhile it does not implement as many features as the reference decoder,
7*01826a49SYabin Cuisuch as the streaming API or content checksums, it is written to be easy to
8*01826a49SYabin Cuifollow and understand, to help understand how the Zstandard format works.
9*01826a49SYabin CuiIt's laid out to match the [format specification],
10*01826a49SYabin Cuiso it can be used to understand how complex segments could be implemented.
11*01826a49SYabin CuiIt also contains implementations of Huffman and FSE table decoding.
12*01826a49SYabin Cui
13*01826a49SYabin Cui[Zstandard format specification]: https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md
14*01826a49SYabin Cui[format specification]: https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md
15*01826a49SYabin Cui
16*01826a49SYabin CuiWhile the library's primary objective is code clarity,
17*01826a49SYabin Cuiit also happens to compile into a small object file.
18*01826a49SYabin CuiThe object file can be made even smaller by removing error messages,
19*01826a49SYabin Cuiusing the macro directive `ZDEC_NO_MESSAGE` at compilation time.
20*01826a49SYabin CuiThis can be reduced even further by foregoing dictionary support,
21*01826a49SYabin Cuiby defining `ZDEC_NO_DICTIONARY`.
22*01826a49SYabin Cui
23*01826a49SYabin Cui`harness.c` provides a simple test harness around the decoder:
24*01826a49SYabin Cui
25*01826a49SYabin Cui    harness <input-file> <output-file> [dictionary]
26*01826a49SYabin Cui
27*01826a49SYabin CuiAs an additional resource to be used with this decoder,
28*01826a49SYabin Cuisee the `decodecorpus` tool in the [tests] directory.
29*01826a49SYabin CuiIt generates valid Zstandard frames that can be used to verify
30*01826a49SYabin Cuia Zstandard decoder implementation.
31*01826a49SYabin CuiNote that to use the tool to verify this decoder implementation,
32*01826a49SYabin Cuithe --content-size flag should be set,
33*01826a49SYabin Cuias this decoder does not handle streaming decoding,
34*01826a49SYabin Cuiand so it must know the decompressed size in advance.
35*01826a49SYabin Cui
36*01826a49SYabin Cui[tests]: https://github.com/facebook/zstd/blob/dev/tests/
37