mirror of
https://github.com/facebook/zstd.git
synced 2025-07-30 22:23:13 +03:00
clarified doc
This commit is contained in:
@ -1,31 +1,31 @@
|
|||||||
Zstandard library : usage examples
|
Zstandard library : usage examples
|
||||||
==================================
|
==================================
|
||||||
|
|
||||||
- [Simple compression](simple_compression.c)
|
- [Simple compression](simple_compression.c) :
|
||||||
Compress a single file.
|
Compress a single file.
|
||||||
Introduces usage of : `ZSTD_compress()`
|
Introduces usage of : `ZSTD_compress()`
|
||||||
|
|
||||||
- [Simple decompression](simple_decompression.c)
|
- [Simple decompression](simple_decompression.c) :
|
||||||
Decompress a single file compressed by zstd.
|
Decompress a single file.
|
||||||
Only compatible with simple compression.
|
Only compatible with simple compression.
|
||||||
Result remains in memory.
|
Result remains in memory.
|
||||||
Introduces usage of : `ZSTD_decompress()`
|
Introduces usage of : `ZSTD_decompress()`
|
||||||
|
|
||||||
- [Dictionary compression](dictionary_compression.c)
|
- [Streaming compression](streaming_compression.c) :
|
||||||
Compress multiple files using the same dictionary.
|
|
||||||
Introduces usage of : `ZSTD_createCDict()` and `ZSTD_compress_usingCDict()`
|
|
||||||
|
|
||||||
- [Dictionary decompression](dictionary_decompression.c)
|
|
||||||
Decompress multiple files using the same dictionary.
|
|
||||||
Result remains in memory.
|
|
||||||
Introduces usage of : `ZSTD_createDDict()` and `ZSTD_decompress_usingDDict()`
|
|
||||||
|
|
||||||
- [Streaming compression](streaming_compression.c)
|
|
||||||
Compress a single file.
|
Compress a single file.
|
||||||
Introduces usage of : `ZSTD_compressStream()`
|
Introduces usage of : `ZSTD_compressStream()`
|
||||||
|
|
||||||
- [Streaming decompression](streaming_decompression.c)
|
- [Streaming decompression](streaming_decompression.c) :
|
||||||
Decompress a single file compressed by zstd.
|
Decompress a single file compressed by zstd.
|
||||||
Compatible with simple and streaming compression.
|
Compatible with both simple and streaming compression.
|
||||||
Result is sent to stdout.
|
Result is sent to stdout.
|
||||||
Introduces usage of : `ZSTD_decompressStream()`
|
Introduces usage of : `ZSTD_decompressStream()`
|
||||||
|
|
||||||
|
- [Dictionary compression](dictionary_compression.c) :
|
||||||
|
Compress multiple files using the same dictionary.
|
||||||
|
Introduces usage of : `ZSTD_createCDict()` and `ZSTD_compress_usingCDict()`
|
||||||
|
|
||||||
|
- [Dictionary decompression](dictionary_decompression.c) :
|
||||||
|
Decompress multiple files using the same dictionary.
|
||||||
|
Result remains in memory.
|
||||||
|
Introduces usage of : `ZSTD_createDDict()` and `ZSTD_decompress_usingDDict()`
|
||||||
|
@ -66,17 +66,16 @@ static void decompressFile_orDie(const char* fname)
|
|||||||
FILE* const fin = fopen_orDie(fname, "rb");
|
FILE* const fin = fopen_orDie(fname, "rb");
|
||||||
size_t const buffInSize = ZSTD_DStreamInSize();
|
size_t const buffInSize = ZSTD_DStreamInSize();
|
||||||
void* const buffIn = malloc_orDie(buffInSize);
|
void* const buffIn = malloc_orDie(buffInSize);
|
||||||
|
FILE* const fout = stdout;
|
||||||
size_t const buffOutSize = ZSTD_DStreamOutSize(); /* Guarantee to successfully flush at least one complete compressed block in all circumstances. */
|
size_t const buffOutSize = ZSTD_DStreamOutSize(); /* Guarantee to successfully flush at least one complete compressed block in all circumstances. */
|
||||||
void* const buffOut = malloc_orDie(buffOutSize);
|
void* const buffOut = malloc_orDie(buffOutSize);
|
||||||
FILE* const fout = stdout;
|
|
||||||
|
|
||||||
ZSTD_DStream* const dstream = ZSTD_createDStream();
|
ZSTD_DStream* const dstream = ZSTD_createDStream();
|
||||||
if (dstream==NULL) { fprintf(stderr, "ZSTD_createDStream() error \n"); exit(10); }
|
if (dstream==NULL) { fprintf(stderr, "ZSTD_createDStream() error \n"); exit(10); }
|
||||||
size_t const initResult = ZSTD_initDStream(dstream);
|
size_t const initResult = ZSTD_initDStream(dstream);
|
||||||
if (ZSTD_isError(initResult)) { fprintf(stderr, "ZSTD_initDStream() error \n"); exit(11); }
|
if (ZSTD_isError(initResult)) { fprintf(stderr, "ZSTD_initDStream() error : %s \n", ZSTD_getErrorName(initResult)); exit(11); }
|
||||||
size_t toRead = initResult;
|
|
||||||
|
|
||||||
size_t read;
|
size_t read, toRead = initResult;
|
||||||
while ( (read = fread_orDie(buffIn, toRead, fin)) ) {
|
while ( (read = fread_orDie(buffIn, toRead, fin)) ) {
|
||||||
ZSTD_inBuffer input = { buffIn, read, 0 };
|
ZSTD_inBuffer input = { buffIn, read, 0 };
|
||||||
while (input.pos < input.size) {
|
while (input.pos < input.size) {
|
||||||
|
Reference in New Issue
Block a user