From 2065879793b745530f21594b521d740f351d18dd Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 17 Aug 2016 01:48:43 +0200 Subject: [PATCH] updated examples --- examples/streaming_compression.c | 16 ++++++++-------- examples/streaming_decompression.c | 11 ++++++----- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/examples/streaming_compression.c b/examples/streaming_compression.c index f99e040c..e2568836 100644 --- a/examples/streaming_compression.c +++ b/examples/streaming_compression.c @@ -93,18 +93,18 @@ static void compressFile_orDie(const char* fname, const char* outName, int cLeve if (ZSTD_isError(initResult)) { fprintf(stderr, "ZSTD_initCStream() error \n"); exit(11); } while( (read = fread_orDie(buffIn, toRead, fin)) ) { - ZSTD_rCursor cursin = { buffIn, read }; - while (cursin.size) { - ZSTD_wCursor cursout = { buffOut, buffOutSize, 0 }; - toRead = ZSTD_compressStream(cstream, &cursout , &cursin); - fwrite_orDie(buffOut, cursout.nbBytesWritten, fout); + ZSTD_inBuffer input = { buffIn, read, 0 }; + while (input.pos < input.size) { + ZSTD_outBuffer output = { buffOut, buffOutSize, 0 }; + toRead = ZSTD_compressStream(cstream, &output , &input); + fwrite_orDie(buffOut, output.pos, fout); } } - ZSTD_wCursor cursout = { buffOut, buffOutSize, 0 }; - size_t const remainingToFlush = ZSTD_endStream(cstream, &cursout); + ZSTD_outBuffer output = { buffOut, buffOutSize, 0 }; + size_t const remainingToFlush = ZSTD_endStream(cstream, &output); if (remainingToFlush) { fprintf(stderr, "not fully flushed"); exit(12); } - fwrite_orDie(buffOut, cursout.nbBytesWritten, fout); + fwrite_orDie(buffOut, output.pos, fout); fclose_orDie(fout); fclose_orDie(fin); diff --git a/examples/streaming_decompression.c b/examples/streaming_decompression.c index 1176cabc..a9efd7a2 100644 --- a/examples/streaming_decompression.c +++ b/examples/streaming_decompression.c @@ -83,11 +83,12 @@ static void decompressFile_orDie(const char* fname) if (ZSTD_isError(initResult)) { fprintf(stderr, "ZSTD_initDStream() error \n"); exit(11); } while( (read = fread_orDie(buffIn, toRead, fin)) ) { - ZSTD_rCursor cursin = { buffIn, read }; - while (cursin.size) { - ZSTD_wCursor cursout = { buffOut, buffOutSize, 0 }; - toRead = ZSTD_decompressStream(dstream, &cursout , &cursin); - /* note : data is just "sinked" into buffOut */ + ZSTD_inBuffer input = { buffIn, read, 0 }; + while (input.pos < input.size) { + ZSTD_outBuffer output = { buffOut, buffOutSize, 0 }; + toRead = ZSTD_decompressStream(dstream, &output , &input); + /* note : data is just "sinked" into buffOut + a more complete example would write it to disk or stdout */ } }