From 7c6bbc3298e2d3b9db62962d39b35d5e179508f9 Mon Sep 17 00:00:00 2001 From: Przemyslaw Skibinski Date: Mon, 5 Dec 2016 18:31:14 +0100 Subject: [PATCH] updated FIO_passThrough --- programs/fileio.c | 10 +++++----- tests/Makefile | 6 ++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index f860145b4..a493e97c5 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -589,15 +589,15 @@ static void FIO_fwriteSparseEnd(FILE* file, unsigned storedSkips) /** FIO_passThrough() : just copy input into output, for compatibility with gzip -df mode @return : 0 (no error) */ -static unsigned FIO_passThrough(FILE* foutput, FILE* finput, void* buffer, size_t bufferSize) +static unsigned FIO_passThrough(FILE* foutput, FILE* finput, void* buffer, size_t bufferSize, size_t alreadyLoaded) { size_t const blockSize = MIN(64 KB, bufferSize); size_t readFromInput = 1; unsigned storedSkips = 0; - /* assumption : first 4 bytes already loaded (magic number detection), and stored within buffer */ - { size_t const sizeCheck = fwrite(buffer, 1, 4, foutput); - if (sizeCheck != 4) EXM_THROW(50, "Pass-through write error"); } + /* assumption : ress->srcBufferLoaded bytes already loaded and stored within buffer */ + { size_t const sizeCheck = fwrite(buffer, 1, alreadyLoaded, foutput); + if (sizeCheck != alreadyLoaded) EXM_THROW(50, "Pass-through write error"); } while (readFromInput) { readFromInput = fread(buffer, 1, blockSize, finput); @@ -751,7 +751,7 @@ static int FIO_decompressSrcFile(dRess_t ress, const char* dstFileName, const ch } else { if (!ZSTD_isFrame(ress.srcBuffer, toRead)) { if ((g_overwrite) && !strcmp (dstFileName, stdoutmark)) { /* pass-through mode */ - unsigned const result = FIO_passThrough(ress.dstFile, srcFile, ress.srcBuffer, ress.srcBufferSize); + unsigned const result = FIO_passThrough(ress.dstFile, srcFile, ress.srcBuffer, ress.srcBufferSize, ress.srcBufferLoaded); if (fclose(srcFile)) EXM_THROW(32, "zstd: %s close error", srcFileName); /* error should never happen */ return result; } else { diff --git a/tests/Makefile b/tests/Makefile index ad367595a..50bb057dc 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -202,6 +202,12 @@ test-gzstd: gzstd $(PRGDIR)/zstd -d README.md.gz test-zstd-speed.py.gz $(PRGDIR)/zstd -d zstd_gz.zst gz_zstd.gz diff -q zstd_gz gz_zstd + echo Hello World ZSTD | $(PRGDIR)/zstd -c - >hello.zst + echo Hello World GZIP | gzip -c - >hello.gz + echo Hello World TEXT >hello.txt + cat hello.zst hello.gz hello.txt >hello_zst_gz_txt.gz + $(PRGDIR)/zstd -dcf hello.* + $(PRGDIR)/zstd -dcf -