blob: cdfe6a3dc847c4a1dc7056162b7c940d4e6ffaec [file] [log] [blame]
Yann Collet4856a002015-01-24 01:58:16 +01001/*
Yann Collet44886612016-02-11 04:17:50 +01002 fileio.c - File i/o handler for zstd
3 Copyright (C) Yann Collet 2013-2016
Yann Collet4856a002015-01-24 01:58:16 +01004
5 GPL v2 License
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 You can contact the author at :
Yann Collet44886612016-02-11 04:17:50 +010022 - zstd homepage : http://www.zstd.net
Yann Collet4856a002015-01-24 01:58:16 +010023*/
24/*
25 Note : this is stand-alone program.
26 It is not part of ZSTD compression library, it is a user program of ZSTD library.
27 The license of ZSTD library is BSD.
28 The license of this file is GPLv2.
29*/
30
Yann Colleteeb8ba12015-10-22 16:55:40 +010031/* *************************************
Yann Colletb1f3f4b2015-10-18 22:18:32 +010032* Tuning options
Yann Colleteeb8ba12015-10-22 16:55:40 +010033***************************************/
Yann Colletb1f3f4b2015-10-18 22:18:32 +010034#ifndef ZSTD_LEGACY_SUPPORT
Yann Collet44886612016-02-11 04:17:50 +010035/* LEGACY_SUPPORT :
Yann Colletb1f3f4b2015-10-18 22:18:32 +010036* decompressor can decode older formats (starting from Zstd 0.1+) */
37# define ZSTD_LEGACY_SUPPORT 1
Yann Collet9f432922015-11-09 17:42:17 +010038#endif
Yann Colletb1f3f4b2015-10-18 22:18:32 +010039
40
Yann Colleteeb8ba12015-10-22 16:55:40 +010041/* *************************************
Yann Collet4856a002015-01-24 01:58:16 +010042* Compiler Options
Yann Colleteeb8ba12015-10-22 16:55:40 +010043***************************************/
inikep0bd0fae2016-05-05 13:10:57 +020044#define _POSIX_SOURCE 1 /* enable %llu on Windows */
Yann Collet4856a002015-01-24 01:58:16 +010045
46
Yann Collet6f3acba2016-02-12 20:19:48 +010047/*-*************************************
Yann Collet4856a002015-01-24 01:58:16 +010048* Includes
Yann Colleteeb8ba12015-10-22 16:55:40 +010049***************************************/
inikep13c84242016-05-05 13:58:56 +020050#include "util.h" /* Compiler options, UTIL_GetFileSize */
Yann Collet9f432922015-11-09 17:42:17 +010051#include <stdio.h> /* fprintf, fopen, fread, _fileno, stdin, stdout */
52#include <stdlib.h> /* malloc, free */
53#include <string.h> /* strcmp, strlen */
54#include <time.h> /* clock */
55#include <errno.h> /* errno */
inikepd5ff2c32016-04-28 14:40:45 +020056
inikepd5ff2c32016-04-28 14:40:45 +020057#include "mem.h"
Yann Collet4856a002015-01-24 01:58:16 +010058#include "fileio.h"
Yann Collet09b21ee2016-03-15 12:56:03 +010059#include "zstd_static.h" /* ZSTD_magicNumber, ZSTD_frameHeaderSize_max */
Yann Collet62ae5fb2016-02-12 18:59:11 +010060#include "zbuff_static.h"
Yann Collet4856a002015-01-24 01:58:16 +010061
Yann Colletb1f3f4b2015-10-18 22:18:32 +010062#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT==1)
Yann Collet6f3acba2016-02-12 20:19:48 +010063# include "zstd_legacy.h" /* ZSTD_isLegacy */
64# include "fileio_legacy.h" /* FIO_decompressLegacyFrame */
Yann Colleteeb8ba12015-10-22 16:55:40 +010065#endif
Yann Colletb1f3f4b2015-10-18 22:18:32 +010066
Yann Collet4856a002015-01-24 01:58:16 +010067
Yann Collet6f3acba2016-02-12 20:19:48 +010068/*-*************************************
Yann Collet4856a002015-01-24 01:58:16 +010069* OS-specific Includes
Yann Colleteeb8ba12015-10-22 16:55:40 +010070***************************************/
Yann Collet4856a002015-01-24 01:58:16 +010071#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
72# include <fcntl.h> /* _O_BINARY */
73# include <io.h> /* _setmode, _isatty */
Yann Colletb5e06dc2015-07-04 23:20:56 -080074# define SET_BINARY_MODE(file) { int unused = _setmode(_fileno(file), _O_BINARY); (void)unused; }
Yann Collet4856a002015-01-24 01:58:16 +010075#else
76# include <unistd.h> /* isatty */
77# define SET_BINARY_MODE(file)
Yann Collet4856a002015-01-24 01:58:16 +010078#endif
79
80
Yann Collet6f3acba2016-02-12 20:19:48 +010081/*-*************************************
Yann Collet4856a002015-01-24 01:58:16 +010082* Constants
Yann Colleteeb8ba12015-10-22 16:55:40 +010083***************************************/
Yann Collet4856a002015-01-24 01:58:16 +010084#define _1BIT 0x01
85#define _2BITS 0x03
86#define _3BITS 0x07
87#define _4BITS 0x0F
88#define _6BITS 0x3F
89#define _8BITS 0xFF
90
Yann Collet88fcd292015-11-25 14:42:45 +010091#define BLOCKSIZE (128 KB)
92#define ROLLBUFFERSIZE (BLOCKSIZE*8*64)
Yann Collet4856a002015-01-24 01:58:16 +010093
Yann Collet6f3acba2016-02-12 20:19:48 +010094#define FIO_FRAMEHEADERSIZE 5 /* as a define, because needed to allocated table on stack */
95#define FSE_CHECKSUM_SEED 0
Yann Collet4856a002015-01-24 01:58:16 +010096
97#define CACHELINE 64
98
Yann Collet6f3acba2016-02-12 20:19:48 +010099#define MAX_DICT_SIZE (1 MB) /* protection against large input (attack scenario) ; can be changed */
100
inikep3c7c3522016-04-22 13:59:05 +0200101#define FNSPACE 30
102
Yann Collet4856a002015-01-24 01:58:16 +0100103
Yann Collet459a6b72016-02-15 20:37:23 +0100104/*-*************************************
Yann Collet4856a002015-01-24 01:58:16 +0100105* Macros
Yann Colleteeb8ba12015-10-22 16:55:40 +0100106***************************************/
Yann Collet4856a002015-01-24 01:58:16 +0100107#define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
108#define DISPLAYLEVEL(l, ...) if (g_displayLevel>=l) { DISPLAY(__VA_ARGS__); }
109static U32 g_displayLevel = 2; /* 0 : no display; 1: errors; 2 : + result + interaction + warnings; 3 : + progression; 4 : + information */
Yann Collet8a1d1a62016-03-10 21:02:25 +0100110void FIO_setNotificationLevel(unsigned level) { g_displayLevel=level; }
Yann Collet4856a002015-01-24 01:58:16 +0100111
112#define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \
113 if ((FIO_GetMilliSpan(g_time) > refreshRate) || (g_displayLevel>=4)) \
114 { g_time = clock(); DISPLAY(__VA_ARGS__); \
115 if (g_displayLevel>=4) fflush(stdout); } }
116static const unsigned refreshRate = 150;
117static clock_t g_time = 0;
118
Yann Colletf6ca09b2016-05-09 04:44:45 +0200119static unsigned FIO_GetMilliSpan(clock_t nPrevious)
120{
121 clock_t const nCurrent = clock();
122 return (unsigned)(((nCurrent - nPrevious) * 1000) / CLOCKS_PER_SEC);
123}
Yann Collet4856a002015-01-24 01:58:16 +0100124
Yann Collet459a6b72016-02-15 20:37:23 +0100125
126/*-*************************************
Yann Collet4856a002015-01-24 01:58:16 +0100127* Local Parameters
Yann Colleteeb8ba12015-10-22 16:55:40 +0100128***************************************/
Yann Collet4856a002015-01-24 01:58:16 +0100129static U32 g_overwrite = 0;
Yann Collet4856a002015-01-24 01:58:16 +0100130void FIO_overwriteMode(void) { g_overwrite=1; }
Yann Collet8a1d1a62016-03-10 21:02:25 +0100131static U32 g_maxWLog = 23;
132void FIO_setMaxWLog(unsigned maxWLog) { g_maxWLog = maxWLog; }
Yann Collet75424d12016-05-23 16:56:56 +0200133static U32 g_sparseFileSupport = 1; /* 0 : no sparse allowed; 1: auto (file yes, stdout no); 2: force sparse */
134void FIO_setSparseWrite(unsigned sparse) { g_sparseFileSupport=sparse; }
Yann Collet4856a002015-01-24 01:58:16 +0100135
136
Yann Collet459a6b72016-02-15 20:37:23 +0100137/*-*************************************
Yann Collet4856a002015-01-24 01:58:16 +0100138* Exceptions
Yann Colleteeb8ba12015-10-22 16:55:40 +0100139***************************************/
140#ifndef DEBUG
141# define DEBUG 0
142#endif
Yann Collet4856a002015-01-24 01:58:16 +0100143#define DEBUGOUTPUT(...) if (DEBUG) DISPLAY(__VA_ARGS__);
144#define EXM_THROW(error, ...) \
145{ \
146 DEBUGOUTPUT("Error defined at %s, line %i : \n", __FILE__, __LINE__); \
147 DISPLAYLEVEL(1, "Error %i : ", error); \
148 DISPLAYLEVEL(1, __VA_ARGS__); \
149 DISPLAYLEVEL(1, "\n"); \
150 exit(error); \
151}
152
153
Yann Collet459a6b72016-02-15 20:37:23 +0100154/*-*************************************
Yann Collet4856a002015-01-24 01:58:16 +0100155* Functions
Yann Colleteeb8ba12015-10-22 16:55:40 +0100156***************************************/
Yann Colletf0624362016-02-12 15:56:46 +0100157static FILE* FIO_openSrcFile(const char* srcFileName)
158{
159 FILE* f;
160
161 if (!strcmp (srcFileName, stdinmark)) {
162 DISPLAYLEVEL(4,"Using stdin for input\n");
163 f = stdin;
164 SET_BINARY_MODE(stdin);
165 } else {
166 f = fopen(srcFileName, "rb");
167 }
168
169 if ( f==NULL ) DISPLAYLEVEL(1, "zstd: %s: No such file\n", srcFileName);
170
171 return f;
172}
173
174
175static FILE* FIO_openDstFile(const char* dstFileName)
176{
177 FILE* f;
178
179 if (!strcmp (dstFileName, stdoutmark)) {
180 DISPLAYLEVEL(4,"Using stdout for output\n");
181 f = stdout;
182 SET_BINARY_MODE(stdout);
Yann Collet75424d12016-05-23 16:56:56 +0200183 if (g_sparseFileSupport==1) {
184 g_sparseFileSupport = 0;
185 DISPLAYLEVEL(4, "Sparse File Support is automatically disabled on stdout ; try --sparse \n");
186 }
Yann Colletf0624362016-02-12 15:56:46 +0100187 } else {
188 if (!g_overwrite) { /* Check if destination file already exists */
189 f = fopen( dstFileName, "rb" );
190 if (f != 0) { /* dest file exists, prompt for overwrite authorization */
191 fclose(f);
192 if (g_displayLevel <= 1) {
193 /* No interaction possible */
194 DISPLAY("zstd: %s already exists; not overwritten \n", dstFileName);
195 return 0;
196 }
197 DISPLAY("zstd: %s already exists; do you wish to overwrite (y/N) ? ", dstFileName);
Yann Collet75424d12016-05-23 16:56:56 +0200198 { int ch = getchar();
Yann Colletf0624362016-02-12 15:56:46 +0100199 if ((ch!='Y') && (ch!='y')) {
200 DISPLAY(" not overwritten \n");
201 return 0;
202 }
203 while ((ch!=EOF) && (ch!='\n')) ch = getchar(); /* flush rest of input line */
204 } } }
205 f = fopen( dstFileName, "wb" );
206 }
207 return f;
208}
209
210
Yann Collet8a1d1a62016-03-10 21:02:25 +0100211/*! FIO_loadFile() :
Yann Collet09b21ee2016-03-15 12:56:03 +0100212* creates a buffer, pointed by `*bufferPtr`,
Yann Collet8a1d1a62016-03-10 21:02:25 +0100213* loads `filename` content into it,
214* up to MAX_DICT_SIZE bytes
Yann Colletdeb078b2015-12-17 20:30:14 +0100215*/
216static size_t FIO_loadFile(void** bufferPtr, const char* fileName)
217{
218 FILE* fileHandle;
219 size_t readSize;
220 U64 fileSize;
221
222 *bufferPtr = NULL;
Yann Collet2ce49232016-02-02 14:36:49 +0100223 if (fileName == NULL) return 0;
Yann Colletdeb078b2015-12-17 20:30:14 +0100224
225 DISPLAYLEVEL(4,"Loading %s as dictionary \n", fileName);
226 fileHandle = fopen(fileName, "rb");
227 if (fileHandle==0) EXM_THROW(31, "Error opening file %s", fileName);
inikep69fcd7c2016-04-28 12:23:33 +0200228 fileSize = UTIL_getFileSize(fileName);
Yann Collet2ce49232016-02-02 14:36:49 +0100229 if (fileSize > MAX_DICT_SIZE) {
Yann Colletdeb078b2015-12-17 20:30:14 +0100230 int seekResult;
231 if (fileSize > 1 GB) EXM_THROW(32, "Dictionary file %s is too large", fileName); /* avoid extreme cases */
232 DISPLAYLEVEL(2,"Dictionary %s is too large : using last %u bytes only \n", fileName, MAX_DICT_SIZE);
233 seekResult = fseek(fileHandle, (long int)(fileSize-MAX_DICT_SIZE), SEEK_SET); /* use end of file */
234 if (seekResult != 0) EXM_THROW(33, "Error seeking into file %s", fileName);
235 fileSize = MAX_DICT_SIZE;
236 }
237 *bufferPtr = (BYTE*)malloc((size_t)fileSize);
238 if (*bufferPtr==NULL) EXM_THROW(34, "Allocation error : not enough memory for dictBuffer");
239 readSize = fread(*bufferPtr, 1, (size_t)fileSize, fileHandle);
240 if (readSize!=fileSize) EXM_THROW(35, "Error reading dictionary file %s", fileName);
241 fclose(fileHandle);
242 return (size_t)fileSize;
243}
244
inikep3c7c3522016-04-22 13:59:05 +0200245#ifndef ZSTD_NOCOMPRESS
Yann Collet4f137032015-12-17 02:23:58 +0100246
Yann Collet8a1d1a62016-03-10 21:02:25 +0100247/*-**********************************************************************
Yann Collet4f137032015-12-17 02:23:58 +0100248* Compression
249************************************************************************/
250typedef struct {
251 void* srcBuffer;
252 size_t srcBufferSize;
253 void* dstBuffer;
254 size_t dstBufferSize;
255 void* dictBuffer;
256 size_t dictBufferSize;
257 ZBUFF_CCtx* ctx;
Yann Colletf0624362016-02-12 15:56:46 +0100258 FILE* dstFile;
Yann Collet459a6b72016-02-15 20:37:23 +0100259 FILE* srcFile;
Yann Collet4f137032015-12-17 02:23:58 +0100260} cRess_t;
261
262static cRess_t FIO_createCResources(const char* dictFileName)
263{
264 cRess_t ress;
265
266 ress.ctx = ZBUFF_createCCtx();
267 if (ress.ctx == NULL) EXM_THROW(30, "Allocation error : can't create ZBUFF context");
268
269 /* Allocate Memory */
270 ress.srcBufferSize = ZBUFF_recommendedCInSize();
271 ress.srcBuffer = malloc(ress.srcBufferSize);
272 ress.dstBufferSize = ZBUFF_recommendedCOutSize();
273 ress.dstBuffer = malloc(ress.dstBufferSize);
274 if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(31, "Allocation error : not enough memory");
275
276 /* dictionary */
Yann Colletdeb078b2015-12-17 20:30:14 +0100277 ress.dictBufferSize = FIO_loadFile(&(ress.dictBuffer), dictFileName);
Yann Collet4f137032015-12-17 02:23:58 +0100278
279 return ress;
280}
281
282static void FIO_freeCResources(cRess_t ress)
283{
284 size_t errorCode;
285 free(ress.srcBuffer);
286 free(ress.dstBuffer);
287 free(ress.dictBuffer);
288 errorCode = ZBUFF_freeCCtx(ress.ctx);
289 if (ZBUFF_isError(errorCode)) EXM_THROW(38, "Error : can't release ZBUFF context resource : %s", ZBUFF_getErrorName(errorCode));
290}
291
292
Yann Colletf0624362016-02-12 15:56:46 +0100293/*! FIO_compressFilename_internal() :
Yann Collet8a1d1a62016-03-10 21:02:25 +0100294 * same as FIO_compressFilename_extRess(), with `ress.desFile` already opened.
Yann Colletf0624362016-02-12 15:56:46 +0100295 * @return : 0 : compression completed correctly,
296 * 1 : missing or pb opening srcFileName
Yann Collet4f137032015-12-17 02:23:58 +0100297 */
Yann Colletf0624362016-02-12 15:56:46 +0100298static int FIO_compressFilename_internal(cRess_t ress,
299 const char* dstFileName, const char* srcFileName,
300 int cLevel)
Yann Collet4f137032015-12-17 02:23:58 +0100301{
Yann Colletf8494622016-05-07 22:43:40 +0200302 FILE* const srcFile = ress.srcFile;
303 FILE* const dstFile = ress.dstFile;
Yann Colletb44be742016-03-26 20:52:14 +0100304 U64 readsize = 0;
Yann Collet4f137032015-12-17 02:23:58 +0100305 U64 compressedfilesize = 0;
inikep69fcd7c2016-04-28 12:23:33 +0200306 U64 const fileSize = UTIL_getFileSize(srcFileName);
Yann Collet4f137032015-12-17 02:23:58 +0100307
Yann Collet4f137032015-12-17 02:23:58 +0100308 /* init */
Yann Colletf8494622016-05-07 22:43:40 +0200309 { ZSTD_parameters params;
310 params.cParams = ZSTD_getCParams(cLevel, fileSize, ress.dictBufferSize);
311 params.fParams.contentSizeFlag = 1;
312 if (g_maxWLog) if (params.cParams.windowLog > g_maxWLog) params.cParams.windowLog = g_maxWLog;
313 { size_t const errorCode = ZBUFF_compressInit_advanced(ress.ctx, ress.dictBuffer, ress.dictBufferSize, params, fileSize);
314 if (ZBUFF_isError(errorCode)) EXM_THROW(21, "Error initializing compression : %s", ZBUFF_getErrorName(errorCode)); }
315 }
Yann Collet4f137032015-12-17 02:23:58 +0100316
317 /* Main compression loop */
Yann Colletb44be742016-03-26 20:52:14 +0100318 readsize = 0;
Yann Collet1c8e1942016-01-26 16:31:22 +0100319 while (1) {
Yann Collet4f137032015-12-17 02:23:58 +0100320 /* Fill input Buffer */
Yann Colletb44be742016-03-26 20:52:14 +0100321 size_t const inSize = fread(ress.srcBuffer, (size_t)1, ress.srcBufferSize, srcFile);
Yann Collet4f137032015-12-17 02:23:58 +0100322 if (inSize==0) break;
Yann Colletb44be742016-03-26 20:52:14 +0100323 readsize += inSize;
324 DISPLAYUPDATE(2, "\rRead : %u MB ", (U32)(readsize>>20));
Yann Collet4f137032015-12-17 02:23:58 +0100325
Yann Colletf0624362016-02-12 15:56:46 +0100326 { /* Compress using buffered streaming */
Yann Collet4f137032015-12-17 02:23:58 +0100327 size_t usedInSize = inSize;
328 size_t cSize = ress.dstBufferSize;
Yann Colletf8494622016-05-07 22:43:40 +0200329 { size_t const result = ZBUFF_compressContinue(ress.ctx, ress.dstBuffer, &cSize, ress.srcBuffer, &usedInSize);
330 if (ZBUFF_isError(result)) EXM_THROW(23, "Compression error : %s ", ZBUFF_getErrorName(result)); }
Yann Collet4f137032015-12-17 02:23:58 +0100331 if (inSize != usedInSize)
332 /* inBuff should be entirely consumed since buffer sizes are recommended ones */
333 EXM_THROW(24, "Compression error : input block not fully consumed");
334
335 /* Write cBlock */
Yann Colletf8494622016-05-07 22:43:40 +0200336 { size_t const sizeCheck = fwrite(ress.dstBuffer, 1, cSize, dstFile);
337 if (sizeCheck!=cSize) EXM_THROW(25, "Write error : cannot write compressed block into %s", dstFileName); }
Yann Collet4f137032015-12-17 02:23:58 +0100338 compressedfilesize += cSize;
339 }
Yann Colletb44be742016-03-26 20:52:14 +0100340 DISPLAYUPDATE(2, "\rRead : %u MB ==> %.2f%% ", (U32)(readsize>>20), (double)compressedfilesize/readsize*100);
Yann Collet4f137032015-12-17 02:23:58 +0100341 }
342
343 /* End of Frame */
Yann Colletb44be742016-03-26 20:52:14 +0100344 { size_t cSize = ress.dstBufferSize;
345 size_t const result = ZBUFF_compressEnd(ress.ctx, ress.dstBuffer, &cSize);
Yann Collet4f137032015-12-17 02:23:58 +0100346 if (result!=0) EXM_THROW(26, "Compression error : cannot create frame end");
347
Yann Colletf8494622016-05-07 22:43:40 +0200348 { size_t const sizeCheck = fwrite(ress.dstBuffer, 1, cSize, dstFile);
349 if (sizeCheck!=cSize) EXM_THROW(27, "Write error : cannot write frame end into %s", dstFileName); }
Yann Collet4f137032015-12-17 02:23:58 +0100350 compressedfilesize += cSize;
351 }
352
353 /* Status */
354 DISPLAYLEVEL(2, "\r%79s\r", "");
355 DISPLAYLEVEL(2,"Compressed %llu bytes into %llu bytes ==> %.2f%%\n",
Yann Colletb44be742016-03-26 20:52:14 +0100356 (unsigned long long)readsize, (unsigned long long) compressedfilesize, (double)compressedfilesize/readsize*100);
Yann Collet4f137032015-12-17 02:23:58 +0100357
Yann Collet4f137032015-12-17 02:23:58 +0100358 return 0;
359}
360
361
Yann Collet459a6b72016-02-15 20:37:23 +0100362/*! FIO_compressFilename_internal() :
Yann Collet09b21ee2016-03-15 12:56:03 +0100363 * same as FIO_compressFilename_extRess(), with ress.destFile already opened (typically stdout)
Yann Collet459a6b72016-02-15 20:37:23 +0100364 * @return : 0 : compression completed correctly,
365 * 1 : missing or pb opening srcFileName
366 */
367static int FIO_compressFilename_srcFile(cRess_t ress,
368 const char* dstFileName, const char* srcFileName,
369 int cLevel)
370{
371 int result;
372
373 /* File check */
374 ress.srcFile = FIO_openSrcFile(srcFileName);
375 if (!ress.srcFile) return 1; /* srcFile could not be opened */
376
377 result = FIO_compressFilename_internal(ress, dstFileName, srcFileName, cLevel);
378
Yann Collet459a6b72016-02-15 20:37:23 +0100379 fclose(ress.srcFile);
380 return result;
381}
382
383
Yann Colletf0624362016-02-12 15:56:46 +0100384/*! FIO_compressFilename_extRess() :
385 * @return : 0 : compression completed correctly,
386 * 1 : missing or pb opening srcFileName
387 */
388static int FIO_compressFilename_extRess(cRess_t ress,
389 const char* dstFileName, const char* srcFileName,
390 int cLevel)
391{
392 int result;
393
Yann Collet459a6b72016-02-15 20:37:23 +0100394 ress.srcFile = FIO_openSrcFile(srcFileName);
395 if (ress.srcFile==0) return 1;
Yann Colletf0624362016-02-12 15:56:46 +0100396 ress.dstFile = FIO_openDstFile(dstFileName);
Yann Collet459a6b72016-02-15 20:37:23 +0100397 if (ress.dstFile==0) { fclose(ress.srcFile); return 1; }
Yann Colletf0624362016-02-12 15:56:46 +0100398
399 result = FIO_compressFilename_internal(ress, dstFileName, srcFileName, cLevel);
Yann Collet09b21ee2016-03-15 12:56:03 +0100400 if (result!=0) remove(dstFileName); /* remove operation artefact */
Chip Turner6de382c2016-03-13 22:24:46 -0700401
Yann Collet459a6b72016-02-15 20:37:23 +0100402 fclose(ress.srcFile); /* no pb to expect : only reading */
Yann Colletf0624362016-02-12 15:56:46 +0100403 if (fclose(ress.dstFile)) EXM_THROW(28, "Write error : cannot properly close %s", dstFileName);
404 return result;
405}
406
407
Yann Collet9d909222015-12-17 14:09:55 +0100408int FIO_compressFilename(const char* dstFileName, const char* srcFileName,
409 const char* dictFileName, int compressionLevel)
Yann Collet4856a002015-01-24 01:58:16 +0100410{
Yann Collet8b23eea2016-05-10 05:37:43 +0200411 clock_t start;
Yann Collet9d909222015-12-17 14:09:55 +0100412 cRess_t ress;
413 int issueWithSrcFile = 0;
Yann Collet88fcd292015-11-25 14:42:45 +0100414
Yann Collet9d909222015-12-17 14:09:55 +0100415 /* Init */
416 start = clock();
417 ress = FIO_createCResources(dictFileName);
Yann Colletf6f3d752015-12-13 13:35:21 +0100418
Yann Collet9d909222015-12-17 14:09:55 +0100419 issueWithSrcFile += FIO_compressFilename_extRess(ress, dstFileName, srcFileName, compressionLevel);
420
Yann Collet9d909222015-12-17 14:09:55 +0100421 FIO_freeCResources(ress);
422
Yann Collet8b23eea2016-05-10 05:37:43 +0200423 { double seconds = (double)(clock() - start) / CLOCKS_PER_SEC;
Yann Collet9d909222015-12-17 14:09:55 +0100424 DISPLAYLEVEL(4, "Completed in %.2f sec \n", seconds);
Yann Colletf6f3d752015-12-13 13:35:21 +0100425 }
Yann Collet9d909222015-12-17 14:09:55 +0100426 return issueWithSrcFile;
Yann Collet4856a002015-01-24 01:58:16 +0100427}
428
429
Yann Collet9d909222015-12-17 14:09:55 +0100430int FIO_compressMultipleFilenames(const char** inFileNamesTable, unsigned nbFiles,
Yann Collet4f137032015-12-17 02:23:58 +0100431 const char* suffix,
432 const char* dictFileName, int compressionLevel)
433{
Yann Collet4f137032015-12-17 02:23:58 +0100434 int missed_files = 0;
Yann Colletf8494622016-05-07 22:43:40 +0200435 char* dstFileName = (char*)malloc(FNSPACE);
Yann Collet4f137032015-12-17 02:23:58 +0100436 size_t dfnSize = FNSPACE;
Yann Colletf8494622016-05-07 22:43:40 +0200437 size_t const suffixSize = suffix ? strlen(suffix) : 0;
Yann Collet4f137032015-12-17 02:23:58 +0100438 cRess_t ress;
439
440 /* init */
441 ress = FIO_createCResources(dictFileName);
442
443 /* loop on each file */
Yann Collet459a6b72016-02-15 20:37:23 +0100444 if (!strcmp(suffix, stdoutmark)) {
Yann Colletf8494622016-05-07 22:43:40 +0200445 unsigned u;
Yann Collet459a6b72016-02-15 20:37:23 +0100446 ress.dstFile = stdout;
447 for (u=0; u<nbFiles; u++)
448 missed_files += FIO_compressFilename_srcFile(ress, stdoutmark,
Yann Collet8a1d1a62016-03-10 21:02:25 +0100449 inFileNamesTable[u], compressionLevel);
Yann Collet459a6b72016-02-15 20:37:23 +0100450 if (fclose(ress.dstFile)) EXM_THROW(29, "Write error : cannot properly close %s", stdoutmark);
451 } else {
Yann Colletf8494622016-05-07 22:43:40 +0200452 unsigned u;
Yann Colletf0624362016-02-12 15:56:46 +0100453 for (u=0; u<nbFiles; u++) {
454 size_t ifnSize = strlen(inFileNamesTable[u]);
455 if (dfnSize <= ifnSize+suffixSize+1) { free(dstFileName); dfnSize = ifnSize + 20; dstFileName = (char*)malloc(dfnSize); }
456 strcpy(dstFileName, inFileNamesTable[u]);
457 strcat(dstFileName, suffix);
458 missed_files += FIO_compressFilename_extRess(ress, dstFileName,
459 inFileNamesTable[u], compressionLevel);
Yann Collet459a6b72016-02-15 20:37:23 +0100460 } }
Yann Collet4f137032015-12-17 02:23:58 +0100461
462 /* Close & Free */
463 FIO_freeCResources(ress);
464 free(dstFileName);
465
466 return missed_files;
467}
468
Yann Colletf8494622016-05-07 22:43:40 +0200469#endif /* #ifndef ZSTD_NOCOMPRESS */
inikep3c7c3522016-04-22 13:59:05 +0200470
Yann Collet4f137032015-12-17 02:23:58 +0100471
inikepdb396432016-04-22 18:22:30 +0200472
473#ifndef ZSTD_NODECOMPRESS
474
Yann Collet4f137032015-12-17 02:23:58 +0100475/* **************************************************************************
476* Decompression
477****************************************************************************/
Yann Colletdeb078b2015-12-17 20:30:14 +0100478typedef struct {
479 void* srcBuffer;
480 size_t srcBufferSize;
481 void* dstBuffer;
482 size_t dstBufferSize;
483 void* dictBuffer;
484 size_t dictBufferSize;
485 ZBUFF_DCtx* dctx;
Yann Collet1f1f2392016-02-12 18:33:26 +0100486 FILE* dstFile;
Yann Colletdeb078b2015-12-17 20:30:14 +0100487} dRess_t;
488
489static dRess_t FIO_createDResources(const char* dictFileName)
490{
491 dRess_t ress;
492
493 /* init */
494 ress.dctx = ZBUFF_createDCtx();
495 if (ress.dctx==NULL) EXM_THROW(60, "Can't create ZBUFF decompression context");
496
497 /* Allocate Memory */
498 ress.srcBufferSize = ZBUFF_recommendedDInSize();
499 ress.srcBuffer = malloc(ress.srcBufferSize);
500 ress.dstBufferSize = ZBUFF_recommendedDOutSize();
501 ress.dstBuffer = malloc(ress.dstBufferSize);
502 if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(61, "Allocation error : not enough memory");
503
504 /* dictionary */
505 ress.dictBufferSize = FIO_loadFile(&(ress.dictBuffer), dictFileName);
506
507 return ress;
508}
509
510static void FIO_freeDResources(dRess_t ress)
511{
Yann Colletf8494622016-05-07 22:43:40 +0200512 size_t const errorCode = ZBUFF_freeDCtx(ress.dctx);
Yann Colletdeb078b2015-12-17 20:30:14 +0100513 if (ZBUFF_isError(errorCode)) EXM_THROW(69, "Error : can't free ZBUFF context resource : %s", ZBUFF_getErrorName(errorCode));
514 free(ress.srcBuffer);
515 free(ress.dstBuffer);
516 free(ress.dictBuffer);
517}
Yann Collet4f137032015-12-17 02:23:58 +0100518
519
Yann Collet75424d12016-05-23 16:56:56 +0200520/** FIO_fwriteSparse() :
521* @return : storedSkips, to be provided to next call to FIO_fwriteSparse() of LZ4IO_fwriteSparseEnd() */
522static unsigned FIO_fwriteSparse(FILE* file, const void* buffer, size_t bufferSize, unsigned storedSkips)
523{
524 const size_t* const bufferT = (const size_t*)buffer; /* Buffer is supposed malloc'ed, hence aligned on size_t */
525 size_t bufferSizeT = bufferSize / sizeof(size_t);
526 const size_t* const bufferTEnd = bufferT + bufferSizeT;
527 const size_t* ptrT = bufferT;
528 static const size_t segmentSizeT = (32 KB) / sizeof(size_t); /* 0-test re-attempted every 32 KB */
529
530 if (!g_sparseFileSupport) { /* normal write */
531 size_t const sizeCheck = fwrite(buffer, 1, bufferSize, file);
532 if (sizeCheck != bufferSize) EXM_THROW(70, "Write error : cannot write decoded block");
533 return 0;
534 }
535
536 /* avoid int overflow */
537 if (storedSkips > 1 GB) {
538 int const seekResult = fseek(file, 1 GB, SEEK_CUR);
539 if (seekResult != 0) EXM_THROW(71, "1 GB skip error (sparse file support)");
540 storedSkips -= 1 GB;
541 }
542
543 while (ptrT < bufferTEnd) {
544 size_t seg0SizeT = segmentSizeT;
545 size_t nb0T;
546
547 /* count leading zeros */
548 if (seg0SizeT > bufferSizeT) seg0SizeT = bufferSizeT;
549 bufferSizeT -= seg0SizeT;
550 for (nb0T=0; (nb0T < seg0SizeT) && (ptrT[nb0T] == 0); nb0T++) ;
551 storedSkips += (unsigned)(nb0T * sizeof(size_t));
552
553 if (nb0T != seg0SizeT) { /* not all 0s */
554 int const seekResult = fseek(file, storedSkips, SEEK_CUR);
555 if (seekResult) EXM_THROW(72, "Sparse skip error ; try --no-sparse");
556 storedSkips = 0;
557 seg0SizeT -= nb0T;
558 ptrT += nb0T;
559 { size_t const sizeCheck = fwrite(ptrT, sizeof(size_t), seg0SizeT, file);
560 if (sizeCheck != seg0SizeT) EXM_THROW(73, "Write error : cannot write decoded block");
561 } }
562 ptrT += seg0SizeT;
563 }
564
565 { static size_t const maskT = sizeof(size_t)-1;
566 if (bufferSize & maskT) { /* size not multiple of sizeof(size_t) : implies end of block */
567 const char* const restStart = (const char*)bufferTEnd;
568 const char* restPtr = restStart;
569 size_t restSize = bufferSize & maskT;
570 const char* const restEnd = restStart + restSize;
571 for ( ; (restPtr < restEnd) && (*restPtr == 0); restPtr++) ;
572 storedSkips += (unsigned) (restPtr - restStart);
573 if (restPtr != restEnd) {
574 int seekResult = fseek(file, storedSkips, SEEK_CUR);
575 if (seekResult) EXM_THROW(74, "Sparse skip error ; try --no-sparse");
576 storedSkips = 0;
577 { size_t const sizeCheck = fwrite(restPtr, 1, restEnd - restPtr, file);
578 if (sizeCheck != (size_t)(restEnd - restPtr)) EXM_THROW(75, "Write error : cannot write decoded end of block");
579 } } } }
580
581 return storedSkips;
582}
583
584static void FIO_fwriteSparseEnd(FILE* file, unsigned storedSkips)
585{
586 if (storedSkips-->0) { /* implies g_sparseFileSupport>0 */
587 int const seekResult = fseek(file, storedSkips, SEEK_CUR);
588 if (seekResult != 0) EXM_THROW(69, "Final skip error (sparse file)\n");
589 { const char lastZeroByte[1] = { 0 };
590 size_t const sizeCheck = fwrite(lastZeroByte, 1, 1, file);
591 if (sizeCheck != 1) EXM_THROW(69, "Write error : cannot write last zero\n");
592 } }
593}
594
Yann Collet09b21ee2016-03-15 12:56:03 +0100595/** FIO_decompressFrame() :
596 @return : size of decoded frame
597*/
Yann Colletdeb078b2015-12-17 20:30:14 +0100598unsigned long long FIO_decompressFrame(dRess_t ress,
599 FILE* foutput, FILE* finput, size_t alreadyLoaded)
Yann Collet4856a002015-01-24 01:58:16 +0100600{
Yann Collet88fcd292015-11-25 14:42:45 +0100601 U64 frameSize = 0;
Yann Collet09b21ee2016-03-15 12:56:03 +0100602 size_t readSize;
Yann Collet75424d12016-05-23 16:56:56 +0200603 U32 storedSkips = 0;
Yann Collet09b21ee2016-03-15 12:56:03 +0100604
605 ZBUFF_decompressInitDictionary(ress.dctx, ress.dictBuffer, ress.dictBufferSize);
606
Yann Colletbd39d542016-05-10 14:14:19 +0200607 /* Header loading (optional, saves one loop) */
608 { size_t const toLoad = ZSTD_frameHeaderSize_min - alreadyLoaded; /* assumption : ZSTD_frameHeaderSize_min >= alreadyLoaded */
609 size_t const loadedSize = fread(((char*)ress.srcBuffer) + alreadyLoaded, 1, toLoad, finput);
Yann Colletd6931172016-05-10 05:56:09 +0200610 readSize = alreadyLoaded + loadedSize;
Yann Collet09b21ee2016-03-15 12:56:03 +0100611 }
Yann Collet4856a002015-01-24 01:58:16 +0100612
Yann Collet4856a002015-01-24 01:58:16 +0100613 /* Main decompression Loop */
Yann Collet2ce49232016-02-02 14:36:49 +0100614 while (1) {
Yann Collet88fcd292015-11-25 14:42:45 +0100615 /* Decode */
Yann Colletdeb078b2015-12-17 20:30:14 +0100616 size_t inSize=readSize, decodedSize=ress.dstBufferSize;
Yann Collet8b23eea2016-05-10 05:37:43 +0200617 size_t const toRead = ZBUFF_decompressContinue(ress.dctx, ress.dstBuffer, &decodedSize, ress.srcBuffer, &inSize);
Yann Collet88fcd292015-11-25 14:42:45 +0100618 if (ZBUFF_isError(toRead)) EXM_THROW(36, "Decoding error : %s", ZBUFF_getErrorName(toRead));
Yann Collet88fcd292015-11-25 14:42:45 +0100619 readSize -= inSize;
Yann Collet88fcd292015-11-25 14:42:45 +0100620
621 /* Write block */
Yann Collet75424d12016-05-23 16:56:56 +0200622 storedSkips = FIO_fwriteSparse(foutput, ress.dstBuffer, decodedSize, storedSkips);
Yann Collet88fcd292015-11-25 14:42:45 +0100623 frameSize += decodedSize;
624 DISPLAYUPDATE(2, "\rDecoded : %u MB... ", (U32)(frameSize>>20) );
625
Yann Collet09b21ee2016-03-15 12:56:03 +0100626 if (toRead == 0) break; /* end of frame */
Yann Colletdeb078b2015-12-17 20:30:14 +0100627 if (readSize) EXM_THROW(38, "Decoding error : should consume entire input");
Yann Collet4856a002015-01-24 01:58:16 +0100628
629 /* Fill input buffer */
Yann Colletdeb078b2015-12-17 20:30:14 +0100630 if (toRead > ress.srcBufferSize) EXM_THROW(34, "too large block");
631 readSize = fread(ress.srcBuffer, 1, toRead, finput);
Yann Collet09b21ee2016-03-15 12:56:03 +0100632 if (readSize != toRead)
633 EXM_THROW(35, "Read error");
Yann Collet4856a002015-01-24 01:58:16 +0100634 }
635
Yann Collet75424d12016-05-23 16:56:56 +0200636 FIO_fwriteSparseEnd(foutput, storedSkips);
637
Yann Collet88fcd292015-11-25 14:42:45 +0100638 return frameSize;
Yann Colletbe50aaa2015-09-10 23:26:09 +0100639}
640
641
Yann Collet1f1f2392016-02-12 18:33:26 +0100642/** FIO_decompressSrcFile() :
643 Decompression `srcFileName` into `ress.dstFile`
644 @return : 0 : OK
645 1 : operation not started
646*/
647static int FIO_decompressSrcFile(dRess_t ress, const char* srcFileName)
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100648{
Yann Colletdeb078b2015-12-17 20:30:14 +0100649 unsigned long long filesize = 0;
Yann Colletf8494622016-05-07 22:43:40 +0200650 FILE* const dstFile = ress.dstFile;
651 FILE* const srcFile = FIO_openSrcFile(srcFileName);
Yann Collet1f1f2392016-02-12 18:33:26 +0100652 if (srcFile==0) return 1;
Yann Collet88fcd292015-11-25 14:42:45 +0100653
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100654 /* for each frame */
Yann Collet2ce49232016-02-02 14:36:49 +0100655 for ( ; ; ) {
Yann Colleta85a8dd2015-11-30 11:53:11 +0100656 /* check magic number -> version */
Yann Collet9e8b09a2016-04-07 19:35:23 +0200657 size_t const toRead = 4;
658 size_t const sizeCheck = fread(ress.srcBuffer, (size_t)1, toRead, srcFile);
Yann Colleta85a8dd2015-11-30 11:53:11 +0100659 if (sizeCheck==0) break; /* no more input */
Yann Collet1f1f2392016-02-12 18:33:26 +0100660 if (sizeCheck != toRead) EXM_THROW(31, "zstd: %s read error : cannot read header", srcFileName);
Yann Colletf8494622016-05-07 22:43:40 +0200661 { U32 const magic = MEM_readLE32(ress.srcBuffer);
662#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
663 if (ZSTD_isLegacy(magic)) {
Yann Collet95af06f2016-05-08 08:23:51 +0200664 filesize += FIO_decompressLegacyFrame(dstFile, srcFile, ress.dictBuffer, ress.dictBufferSize, magic);
Yann Colletf8494622016-05-07 22:43:40 +0200665 continue;
666 }
Yann Collet8b23eea2016-05-10 05:37:43 +0200667#endif
Yann Colletf8494622016-05-07 22:43:40 +0200668 if (magic != ZSTD_MAGICNUMBER) {
669 DISPLAYLEVEL(1, "zstd: %s: not in zstd format \n", srcFileName);
670 return 1;
671 } }
Yann Colletdeb078b2015-12-17 20:30:14 +0100672 filesize += FIO_decompressFrame(ress, dstFile, srcFile, toRead);
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100673 }
674
Yann Colletdeb078b2015-12-17 20:30:14 +0100675 /* Final Status */
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100676 DISPLAYLEVEL(2, "\r%79s\r", "");
Yann Colletdeb078b2015-12-17 20:30:14 +0100677 DISPLAYLEVEL(2, "Successfully decoded %llu bytes \n", filesize);
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100678
Yann Colletdeb078b2015-12-17 20:30:14 +0100679 /* Close */
680 fclose(srcFile);
Yann Collet1f1f2392016-02-12 18:33:26 +0100681 return 0;
682}
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100683
Yann Collet1f1f2392016-02-12 18:33:26 +0100684
685/** FIO_decompressFile_extRess() :
686 decompress `srcFileName` into `dstFileName`
687 @return : 0 : OK
688 1 : operation aborted (src not available, dst already taken, etc.)
689*/
690static int FIO_decompressFile_extRess(dRess_t ress,
691 const char* dstFileName, const char* srcFileName)
692{
Chip Turner6de382c2016-03-13 22:24:46 -0700693 int result;
Yann Collet1f1f2392016-02-12 18:33:26 +0100694 ress.dstFile = FIO_openDstFile(dstFileName);
695 if (ress.dstFile==0) return 1;
696
Chip Turner6de382c2016-03-13 22:24:46 -0700697 result = FIO_decompressSrcFile(ress, srcFileName);
Yann Collet8b23eea2016-05-10 05:37:43 +0200698 if (result != 0) remove(dstFileName);
Yann Collet1f1f2392016-02-12 18:33:26 +0100699
700 if (fclose(ress.dstFile)) EXM_THROW(38, "Write error : cannot properly close %s", dstFileName);
Chip Turner6de382c2016-03-13 22:24:46 -0700701 return result;
Yann Colletb1f3f4b2015-10-18 22:18:32 +0100702}
703
704
Yann Colletdeb078b2015-12-17 20:30:14 +0100705int FIO_decompressFilename(const char* dstFileName, const char* srcFileName,
706 const char* dictFileName)
707{
708 int missingFiles = 0;
709 dRess_t ress = FIO_createDResources(dictFileName);
710
711 missingFiles += FIO_decompressFile_extRess(ress, dstFileName, srcFileName);
712
713 FIO_freeDResources(ress);
714 return missingFiles;
715}
716
717
718#define MAXSUFFIXSIZE 8
719int FIO_decompressMultipleFilenames(const char** srcNamesTable, unsigned nbFiles,
720 const char* suffix,
721 const char* dictFileName)
722{
Yann Colletdeb078b2015-12-17 20:30:14 +0100723 int skippedFiles = 0;
724 int missingFiles = 0;
Yann Collet8b23eea2016-05-10 05:37:43 +0200725 dRess_t ress = FIO_createDResources(dictFileName);
Yann Colletdeb078b2015-12-17 20:30:14 +0100726
Yann Colletaccfd802016-02-15 19:33:16 +0100727 if (!strcmp(suffix, stdoutmark) || !strcmp(suffix, nulmark)) {
Yann Colletf8494622016-05-07 22:43:40 +0200728 unsigned u;
Yann Colletaccfd802016-02-15 19:33:16 +0100729 ress.dstFile = FIO_openDstFile(suffix);
730 if (ress.dstFile == 0) EXM_THROW(71, "cannot open %s", suffix);
731 for (u=0; u<nbFiles; u++)
732 missingFiles += FIO_decompressSrcFile(ress, srcNamesTable[u]);
733 if (fclose(ress.dstFile)) EXM_THROW(39, "Write error : cannot properly close %s", stdoutmark);
734 } else {
Yann Collet8b23eea2016-05-10 05:37:43 +0200735 size_t const suffixSize = suffix ? strlen(suffix) : 0;
736 size_t dfnSize = FNSPACE;
Yann Colletf8494622016-05-07 22:43:40 +0200737 unsigned u;
Yann Collet8b23eea2016-05-10 05:37:43 +0200738 char* dstFileName = (char*)malloc(FNSPACE);
739 if (dstFileName==NULL) EXM_THROW(70, "not enough memory for dstFileName");
Yann Collet1f1f2392016-02-12 18:33:26 +0100740 for (u=0; u<nbFiles; u++) { /* create dstFileName */
Yann Collet8b23eea2016-05-10 05:37:43 +0200741 const char* const srcFileName = srcNamesTable[u];
742 size_t const sfnSize = strlen(srcFileName);
743 const char* const suffixPtr = srcFileName + sfnSize - suffixSize;
Yann Colletaccfd802016-02-15 19:33:16 +0100744 if (dfnSize+suffixSize <= sfnSize+1) {
745 free(dstFileName);
746 dfnSize = sfnSize + 20;
747 dstFileName = (char*)malloc(dfnSize);
748 if (dstFileName==NULL) EXM_THROW(71, "not enough memory for dstFileName");
749 }
750 if (sfnSize <= suffixSize || strcmp(suffixPtr, suffix) != 0) {
Yann Collet1f1f2392016-02-12 18:33:26 +0100751 DISPLAYLEVEL(1, "zstd: %s: unknown suffix (%4s expected) -- ignored \n", srcFileName, suffix);
752 skippedFiles++;
753 continue;
754 }
755 memcpy(dstFileName, srcFileName, sfnSize - suffixSize);
756 dstFileName[sfnSize-suffixSize] = '\0';
Yann Colletdeb078b2015-12-17 20:30:14 +0100757
Yann Collet1f1f2392016-02-12 18:33:26 +0100758 missingFiles += FIO_decompressFile_extRess(ress, dstFileName, srcFileName);
Yann Collet8b23eea2016-05-10 05:37:43 +0200759 }
760 free(dstFileName);
761 }
Yann Colletdeb078b2015-12-17 20:30:14 +0100762
763 FIO_freeDResources(ress);
Yann Colletdeb078b2015-12-17 20:30:14 +0100764 return missingFiles + skippedFiles;
765}
Yann Colletaccfd802016-02-15 19:33:16 +0100766
Yann Collet8b23eea2016-05-10 05:37:43 +0200767#endif /* #ifndef ZSTD_NODECOMPRESS */