mirror of
https://github.com/facebook/zstd.git
synced 2025-07-29 11:21:22 +03:00
added : -m : decompress multiple files
This commit is contained in:
2
Makefile
2
Makefile
@ -32,7 +32,7 @@
|
|||||||
# ################################################################
|
# ################################################################
|
||||||
|
|
||||||
# Version number
|
# Version number
|
||||||
export VERSION := 0.4.4
|
export VERSION := 0.4.5
|
||||||
|
|
||||||
PRGDIR = programs
|
PRGDIR = programs
|
||||||
ZSTDDIR = lib
|
ZSTDDIR = lib
|
||||||
|
3
NEWS
3
NEWS
@ -1,3 +1,6 @@
|
|||||||
|
v0.4.5
|
||||||
|
new : -m/--multiple : compress/decompress multiple files
|
||||||
|
|
||||||
v0.4.4
|
v0.4.4
|
||||||
Fixed : high compression modes for Windows 32 bits
|
Fixed : high compression modes for Windows 32 bits
|
||||||
new : external dictionary API extended to buffered mode and accessible through command line
|
new : external dictionary API extended to buffered mode and accessible through command line
|
||||||
|
@ -62,7 +62,7 @@ extern "C" {
|
|||||||
***************************************/
|
***************************************/
|
||||||
#define ZSTD_VERSION_MAJOR 0 /* for breaking interface changes */
|
#define ZSTD_VERSION_MAJOR 0 /* for breaking interface changes */
|
||||||
#define ZSTD_VERSION_MINOR 4 /* for new (non-breaking) interface capabilities */
|
#define ZSTD_VERSION_MINOR 4 /* for new (non-breaking) interface capabilities */
|
||||||
#define ZSTD_VERSION_RELEASE 3 /* for tweaks, bug-fixes, or development */
|
#define ZSTD_VERSION_RELEASE 5 /* for tweaks, bug-fixes, or development */
|
||||||
#define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
|
#define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
|
||||||
ZSTDLIB_API unsigned ZSTD_versionNumber (void);
|
ZSTDLIB_API unsigned ZSTD_versionNumber (void);
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
# fullbench32: Same as fullbench, but forced to compile in 32-bits mode
|
# fullbench32: Same as fullbench, but forced to compile in 32-bits mode
|
||||||
# ##########################################################################
|
# ##########################################################################
|
||||||
|
|
||||||
VERSION?= 0.4.4
|
VERSION?= 0.4.5
|
||||||
|
|
||||||
DESTDIR?=
|
DESTDIR?=
|
||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
|
@ -175,52 +175,6 @@ static unsigned FIO_GetMilliSpan(clock_t nPrevious)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void FIO_getFileHandles(FILE** pfinput, FILE** pfoutput, const char* input_filename, const char* output_filename)
|
|
||||||
{
|
|
||||||
if (!strcmp (input_filename, stdinmark))
|
|
||||||
{
|
|
||||||
DISPLAYLEVEL(4,"Using stdin for input\n");
|
|
||||||
*pfinput = stdin;
|
|
||||||
SET_BINARY_MODE(stdin);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*pfinput = fopen(input_filename, "rb");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strcmp (output_filename, stdoutmark))
|
|
||||||
{
|
|
||||||
DISPLAYLEVEL(4,"Using stdout for output\n");
|
|
||||||
*pfoutput = stdout;
|
|
||||||
SET_BINARY_MODE(stdout);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Check if destination file already exists */
|
|
||||||
*pfoutput=0;
|
|
||||||
if (strcmp(output_filename,nulmark)) *pfoutput = fopen( output_filename, "rb" );
|
|
||||||
if (*pfoutput!=0)
|
|
||||||
{
|
|
||||||
fclose(*pfoutput);
|
|
||||||
if (!g_overwrite)
|
|
||||||
{
|
|
||||||
char ch='N';
|
|
||||||
if (g_displayLevel <= 1) /* No interaction possible */
|
|
||||||
EXM_THROW(11, "Operation aborted : %s already exists", output_filename);
|
|
||||||
DISPLAYLEVEL(2, "Warning : %s already exists\n", output_filename);
|
|
||||||
DISPLAYLEVEL(2, "Overwrite ? (y/N) : ");
|
|
||||||
ch = (char)getchar();
|
|
||||||
if ((ch!='Y') && (ch!='y')) EXM_THROW(11, "Operation aborted : %s already exists", output_filename);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*pfoutput = fopen( output_filename, "wb" );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( *pfinput==0 ) EXM_THROW(12, "Pb opening src : %s", input_filename);
|
|
||||||
if ( *pfoutput==0) EXM_THROW(13, "Pb opening dst : %s", output_filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static U64 FIO_getFileSize(const char* infilename)
|
static U64 FIO_getFileSize(const char* infilename)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
@ -273,12 +227,20 @@ static int FIO_getFiles(FILE** fileOutPtr, FILE** fileInPtr,
|
|||||||
/* prompt for overwrite authorization */
|
/* prompt for overwrite authorization */
|
||||||
int ch = 'N';
|
int ch = 'N';
|
||||||
fclose(*fileOutPtr);
|
fclose(*fileOutPtr);
|
||||||
DISPLAYLEVEL(2, "Warning : %s already exists\n", dstFileName);
|
DISPLAY("Warning : %s already exists \n", dstFileName);
|
||||||
if ((g_displayLevel <= 1) || (*fileInPtr == stdin))
|
if ((g_displayLevel <= 1) || (*fileInPtr == stdin))
|
||||||
EXM_THROW(11, "Operation aborted : %s already exists", dstFileName); /* No interaction possible */
|
{
|
||||||
DISPLAYLEVEL(2, "Overwrite ? (y/N) : ");
|
/* No interaction possible */
|
||||||
|
DISPLAY("Operation aborted : %s already exists \n", dstFileName);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
DISPLAY("Overwrite ? (y/N) : ");
|
||||||
while((ch = getchar()) != '\n' && ch != EOF); /* flush integrated */
|
while((ch = getchar()) != '\n' && ch != EOF); /* flush integrated */
|
||||||
if ((ch!='Y') && (ch!='y')) EXM_THROW(12, "No. Operation aborted : %s already exists", dstFileName);
|
if ((ch!='Y') && (ch!='y'))
|
||||||
|
{
|
||||||
|
DISPLAY("No. Operation aborted : %s already exists \n", dstFileName);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*fileOutPtr = fopen( dstFileName, "wb" );
|
*fileOutPtr = fopen( dstFileName, "wb" );
|
||||||
@ -289,6 +251,42 @@ static int FIO_getFiles(FILE** fileOutPtr, FILE** fileInPtr,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!FIO_loadFile
|
||||||
|
* creates a buffer, pointed by *bufferPtr,
|
||||||
|
* loads "filename" content into it
|
||||||
|
* up to MAX_DICT_SIZE bytes
|
||||||
|
*/
|
||||||
|
static size_t FIO_loadFile(void** bufferPtr, const char* fileName)
|
||||||
|
{
|
||||||
|
FILE* fileHandle;
|
||||||
|
size_t readSize;
|
||||||
|
U64 fileSize;
|
||||||
|
|
||||||
|
*bufferPtr = NULL;
|
||||||
|
if (fileName == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
DISPLAYLEVEL(4,"Loading %s as dictionary \n", fileName);
|
||||||
|
fileHandle = fopen(fileName, "rb");
|
||||||
|
if (fileHandle==0) EXM_THROW(31, "Error opening file %s", fileName);
|
||||||
|
fileSize = FIO_getFileSize(fileName);
|
||||||
|
if (fileSize > MAX_DICT_SIZE)
|
||||||
|
{
|
||||||
|
int seekResult;
|
||||||
|
if (fileSize > 1 GB) EXM_THROW(32, "Dictionary file %s is too large", fileName); /* avoid extreme cases */
|
||||||
|
DISPLAYLEVEL(2,"Dictionary %s is too large : using last %u bytes only \n", fileName, MAX_DICT_SIZE);
|
||||||
|
seekResult = fseek(fileHandle, (long int)(fileSize-MAX_DICT_SIZE), SEEK_SET); /* use end of file */
|
||||||
|
if (seekResult != 0) EXM_THROW(33, "Error seeking into file %s", fileName);
|
||||||
|
fileSize = MAX_DICT_SIZE;
|
||||||
|
}
|
||||||
|
*bufferPtr = (BYTE*)malloc((size_t)fileSize);
|
||||||
|
if (*bufferPtr==NULL) EXM_THROW(34, "Allocation error : not enough memory for dictBuffer");
|
||||||
|
readSize = fread(*bufferPtr, 1, (size_t)fileSize, fileHandle);
|
||||||
|
if (readSize!=fileSize) EXM_THROW(35, "Error reading dictionary file %s", fileName);
|
||||||
|
fclose(fileHandle);
|
||||||
|
return (size_t)fileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* **********************************************************************
|
/* **********************************************************************
|
||||||
* Compression
|
* Compression
|
||||||
@ -318,33 +316,7 @@ static cRess_t FIO_createCResources(const char* dictFileName)
|
|||||||
if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(31, "Allocation error : not enough memory");
|
if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(31, "Allocation error : not enough memory");
|
||||||
|
|
||||||
/* dictionary */
|
/* dictionary */
|
||||||
ress.dictBuffer = NULL;
|
ress.dictBufferSize = FIO_loadFile(&(ress.dictBuffer), dictFileName);
|
||||||
ress.dictBufferSize = 0;
|
|
||||||
if (dictFileName)
|
|
||||||
{
|
|
||||||
FILE* dictHandle;
|
|
||||||
size_t readSize;
|
|
||||||
U64 dictSize;
|
|
||||||
DISPLAYLEVEL(4,"Using %s as dictionary \n", dictFileName);
|
|
||||||
dictHandle = fopen(dictFileName, "rb");
|
|
||||||
if (dictHandle==0) EXM_THROW(31, "Error opening dictionary file %s", dictFileName);
|
|
||||||
dictSize = FIO_getFileSize(dictFileName);
|
|
||||||
if (dictSize > MAX_DICT_SIZE)
|
|
||||||
{
|
|
||||||
int seekResult;
|
|
||||||
if (dictSize > 1 GB) EXM_THROW(32, "Dictionary file %s is too large", dictFileName); /* avoid extreme cases */
|
|
||||||
DISPLAYLEVEL(2,"Dictionary %s is too large : using last %u bytes only \n", dictFileName, MAX_DICT_SIZE);
|
|
||||||
seekResult = fseek(dictHandle, (long int)(dictSize-MAX_DICT_SIZE), SEEK_SET); /* use end of file */
|
|
||||||
if (seekResult != 0) EXM_THROW(33, "Error seeking into dictionary file %s", dictFileName);
|
|
||||||
dictSize = MAX_DICT_SIZE;
|
|
||||||
}
|
|
||||||
ress.dictBuffer = (BYTE*)malloc((size_t)dictSize);
|
|
||||||
if (ress.dictBuffer==NULL) EXM_THROW(34, "Allocation error : not enough memory for dictBuffer");
|
|
||||||
readSize = fread(ress.dictBuffer, 1, (size_t)dictSize, dictHandle);
|
|
||||||
if (readSize!=dictSize) EXM_THROW(35, "Error reading dictionary file %s", dictFileName);
|
|
||||||
fclose(dictHandle);
|
|
||||||
ress.dictBufferSize = (size_t)dictSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ress;
|
return ress;
|
||||||
}
|
}
|
||||||
@ -504,48 +476,80 @@ int FIO_compressMultipleFilenames(const char** inFileNamesTable, unsigned nbFile
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* **************************************************************************
|
/* **************************************************************************
|
||||||
* Decompression
|
* Decompression
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
typedef struct {
|
||||||
|
void* srcBuffer;
|
||||||
|
size_t srcBufferSize;
|
||||||
|
void* dstBuffer;
|
||||||
|
size_t dstBufferSize;
|
||||||
|
void* dictBuffer;
|
||||||
|
size_t dictBufferSize;
|
||||||
|
ZBUFF_DCtx* dctx;
|
||||||
|
} dRess_t;
|
||||||
|
|
||||||
|
static dRess_t FIO_createDResources(const char* dictFileName)
|
||||||
|
{
|
||||||
|
dRess_t ress;
|
||||||
|
|
||||||
|
/* init */
|
||||||
|
ress.dctx = ZBUFF_createDCtx();
|
||||||
|
if (ress.dctx==NULL) EXM_THROW(60, "Can't create ZBUFF decompression context");
|
||||||
|
|
||||||
|
/* Allocate Memory */
|
||||||
|
ress.srcBufferSize = ZBUFF_recommendedDInSize();
|
||||||
|
ress.srcBuffer = malloc(ress.srcBufferSize);
|
||||||
|
ress.dstBufferSize = ZBUFF_recommendedDOutSize();
|
||||||
|
ress.dstBuffer = malloc(ress.dstBufferSize);
|
||||||
|
if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(61, "Allocation error : not enough memory");
|
||||||
|
|
||||||
|
/* dictionary */
|
||||||
|
ress.dictBufferSize = FIO_loadFile(&(ress.dictBuffer), dictFileName);
|
||||||
|
|
||||||
|
return ress;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void FIO_freeDResources(dRess_t ress)
|
||||||
|
{
|
||||||
|
size_t errorCode = ZBUFF_freeDCtx(ress.dctx);
|
||||||
|
if (ZBUFF_isError(errorCode)) EXM_THROW(69, "Error : can't free ZBUFF context resource : %s", ZBUFF_getErrorName(errorCode));
|
||||||
|
free(ress.srcBuffer);
|
||||||
|
free(ress.dstBuffer);
|
||||||
|
free(ress.dictBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long FIO_decompressFrame(FILE* foutput, FILE* finput,
|
unsigned long long FIO_decompressFrame(dRess_t ress,
|
||||||
BYTE* inBuff, size_t inBuffSize, size_t alreadyLoaded,
|
FILE* foutput, FILE* finput, size_t alreadyLoaded)
|
||||||
BYTE* outBuff, size_t outBuffSize,
|
|
||||||
BYTE* dictBuff, size_t dictSize,
|
|
||||||
ZBUFF_DCtx* dctx)
|
|
||||||
{
|
{
|
||||||
U64 frameSize = 0;
|
U64 frameSize = 0;
|
||||||
size_t readSize=alreadyLoaded;
|
size_t readSize=alreadyLoaded;
|
||||||
|
|
||||||
/* Main decompression Loop */
|
/* Main decompression Loop */
|
||||||
ZBUFF_decompressInit(dctx);
|
ZBUFF_decompressInit(ress.dctx);
|
||||||
ZBUFF_decompressWithDictionary(dctx, dictBuff, dictSize);
|
ZBUFF_decompressWithDictionary(ress.dctx, ress.dictBuffer, ress.dictBufferSize);
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
/* Decode */
|
/* Decode */
|
||||||
size_t sizeCheck;
|
size_t sizeCheck;
|
||||||
size_t inSize=readSize, decodedSize=outBuffSize;
|
size_t inSize=readSize, decodedSize=ress.dstBufferSize;
|
||||||
size_t inStart=0;
|
size_t toRead = ZBUFF_decompressContinue(ress.dctx, ress.dstBuffer, &decodedSize, ress.srcBuffer, &inSize);
|
||||||
size_t toRead = ZBUFF_decompressContinue(dctx, outBuff, &decodedSize, inBuff+inStart, &inSize);
|
|
||||||
if (ZBUFF_isError(toRead)) EXM_THROW(36, "Decoding error : %s", ZBUFF_getErrorName(toRead));
|
if (ZBUFF_isError(toRead)) EXM_THROW(36, "Decoding error : %s", ZBUFF_getErrorName(toRead));
|
||||||
readSize -= inSize;
|
readSize -= inSize;
|
||||||
inStart += inSize;
|
|
||||||
|
|
||||||
/* Write block */
|
/* Write block */
|
||||||
sizeCheck = fwrite(outBuff, 1, decodedSize, foutput);
|
sizeCheck = fwrite(ress.dstBuffer, 1, decodedSize, foutput);
|
||||||
if (sizeCheck != decodedSize) EXM_THROW(37, "Write error : unable to write data block to destination file");
|
if (sizeCheck != decodedSize) EXM_THROW(37, "Write error : unable to write data block to destination file");
|
||||||
frameSize += decodedSize;
|
frameSize += decodedSize;
|
||||||
DISPLAYUPDATE(2, "\rDecoded : %u MB... ", (U32)(frameSize>>20) );
|
DISPLAYUPDATE(2, "\rDecoded : %u MB... ", (U32)(frameSize>>20) );
|
||||||
|
|
||||||
if (toRead == 0) break;
|
if (toRead == 0) break;
|
||||||
if (readSize) continue; /* still some data left within inBuff */
|
if (readSize) EXM_THROW(38, "Decoding error : should consume entire input");
|
||||||
|
|
||||||
/* Fill input buffer */
|
/* Fill input buffer */
|
||||||
if (toRead > inBuffSize) EXM_THROW(34, "too large block");
|
if (toRead > ress.srcBufferSize) EXM_THROW(34, "too large block");
|
||||||
readSize = fread(inBuff, 1, toRead, finput);
|
readSize = fread(ress.srcBuffer, 1, toRead, finput);
|
||||||
if (readSize != toRead) EXM_THROW(35, "Read error");
|
if (readSize != toRead) EXM_THROW(35, "Read error");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -553,88 +557,96 @@ unsigned long long FIO_decompressFrame(FILE* foutput, FILE* finput,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long FIO_decompressFilename(const char* output_filename, const char* input_filename, const char* dictFileName)
|
static int FIO_decompressFile_extRess(dRess_t ress,
|
||||||
|
const char* dstFileName, const char* srcFileName)
|
||||||
{
|
{
|
||||||
FILE* finput, *foutput;
|
unsigned long long filesize = 0;
|
||||||
BYTE* inBuff=NULL;
|
FILE* srcFile;
|
||||||
size_t inBuffSize = ZBUFF_recommendedDInSize();
|
FILE* dstFile;
|
||||||
BYTE* outBuff=NULL;
|
|
||||||
size_t outBuffSize = ZBUFF_recommendedDOutSize();
|
|
||||||
BYTE* dictBuff=NULL;
|
|
||||||
size_t dictSize = 0;
|
|
||||||
U64 filesize = 0;
|
|
||||||
size_t toRead;
|
|
||||||
|
|
||||||
/* dictionary */
|
|
||||||
if (dictFileName)
|
|
||||||
{
|
|
||||||
FILE* dictHandle;
|
|
||||||
size_t readSize;
|
|
||||||
DISPLAYLEVEL(4,"Using %s as dictionary \n", dictFileName);
|
|
||||||
dictHandle = fopen(dictFileName, "rb");
|
|
||||||
if (dictHandle==0) EXM_THROW(21, "Error opening dictionary file %s", dictFileName);
|
|
||||||
dictSize = (size_t)FIO_getFileSize(dictFileName);
|
|
||||||
if (dictSize > MAX_DICT_SIZE)
|
|
||||||
{
|
|
||||||
int seekResult;
|
|
||||||
if (dictSize > 1 GB) EXM_THROW(21, "Dictionary file %s is too large", dictFileName); /* avoid extreme cases */
|
|
||||||
DISPLAYLEVEL(2,"Dictionary %s is too large : using last %u bytes only \n", dictFileName, MAX_DICT_SIZE);
|
|
||||||
seekResult = fseek(dictHandle, (long int)(dictSize-MAX_DICT_SIZE), SEEK_SET); /* use end of file */
|
|
||||||
if (seekResult != 0) EXM_THROW(21, "Error seeking into dictionary file %s", dictFileName);
|
|
||||||
dictSize = MAX_DICT_SIZE;
|
|
||||||
}
|
|
||||||
dictBuff = (BYTE*)malloc(dictSize);
|
|
||||||
if (dictBuff==NULL) EXM_THROW(20, "Allocation error : not enough memory for dictBuff");
|
|
||||||
readSize = fread(dictBuff, 1, (size_t)dictSize, dictHandle);
|
|
||||||
if (readSize!=dictSize) EXM_THROW(21, "Error reading dictionary file %s", dictFileName);
|
|
||||||
fclose(dictHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Init */
|
/* Init */
|
||||||
ZBUFF_DCtx* dctx = ZBUFF_createDCtx();
|
if (FIO_getFiles(&dstFile, &srcFile, dstFileName, srcFileName)) return 1;
|
||||||
FIO_getFileHandles(&finput, &foutput, input_filename, output_filename);
|
|
||||||
|
|
||||||
/* Allocate Memory (if needed) */
|
|
||||||
inBuff = (BYTE*)malloc(inBuffSize);
|
|
||||||
outBuff = (BYTE*)malloc(outBuffSize);
|
|
||||||
if (!inBuff || !outBuff) EXM_THROW(33, "Allocation error : not enough memory");
|
|
||||||
|
|
||||||
/* for each frame */
|
/* for each frame */
|
||||||
for ( ; ; )
|
for ( ; ; )
|
||||||
{
|
{
|
||||||
size_t sizeCheck;
|
size_t sizeCheck;
|
||||||
/* check magic number -> version */
|
/* check magic number -> version */
|
||||||
toRead = 4;
|
size_t toRead = 4;
|
||||||
sizeCheck = fread(inBuff, (size_t)1, toRead, finput);
|
sizeCheck = fread(ress.srcBuffer, (size_t)1, toRead, srcFile);
|
||||||
if (sizeCheck==0) break; /* no more input */
|
if (sizeCheck==0) break; /* no more input */
|
||||||
if (sizeCheck != toRead) EXM_THROW(31, "Read error : cannot read header");
|
if (sizeCheck != toRead) EXM_THROW(31, "Read error : cannot read header");
|
||||||
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT==1)
|
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT==1)
|
||||||
if (ZSTD_isLegacy(MEM_readLE32(inBuff)))
|
if (ZSTD_isLegacy(MEM_readLE32(ress.srcBuffer)))
|
||||||
{
|
{
|
||||||
filesize += FIO_decompressLegacyFrame(foutput, finput, MEM_readLE32(inBuff));
|
filesize += FIO_decompressLegacyFrame(dstFile, srcFile, MEM_readLE32(ress.srcBuffer));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif /* ZSTD_LEGACY_SUPPORT */
|
#endif /* ZSTD_LEGACY_SUPPORT */
|
||||||
|
|
||||||
filesize += FIO_decompressFrame(foutput, finput,
|
filesize += FIO_decompressFrame(ress, dstFile, srcFile, toRead);
|
||||||
inBuff, inBuffSize, toRead,
|
|
||||||
outBuff, outBuffSize,
|
|
||||||
dictBuff, dictSize,
|
|
||||||
dctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Final Status */
|
||||||
DISPLAYLEVEL(2, "\r%79s\r", "");
|
DISPLAYLEVEL(2, "\r%79s\r", "");
|
||||||
DISPLAYLEVEL(2, "Decoded %llu bytes \n", (long long unsigned)filesize);
|
DISPLAYLEVEL(2, "Successfully decoded %llu bytes \n", filesize);
|
||||||
|
|
||||||
/* clean */
|
/* Close */
|
||||||
free(inBuff);
|
fclose(srcFile);
|
||||||
free(outBuff);
|
if (fclose(dstFile)) EXM_THROW(38, "Write error : cannot properly close %s", dstFileName);
|
||||||
free(dictBuff);
|
|
||||||
ZBUFF_freeDCtx(dctx);
|
|
||||||
fclose(finput);
|
|
||||||
if (fclose(foutput)) EXM_THROW(38, "Write error : cannot properly close %s", output_filename);
|
|
||||||
|
|
||||||
return filesize;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int FIO_decompressFilename(const char* dstFileName, const char* srcFileName,
|
||||||
|
const char* dictFileName)
|
||||||
|
{
|
||||||
|
int missingFiles = 0;
|
||||||
|
dRess_t ress = FIO_createDResources(dictFileName);
|
||||||
|
|
||||||
|
missingFiles += FIO_decompressFile_extRess(ress, dstFileName, srcFileName);
|
||||||
|
|
||||||
|
FIO_freeDResources(ress);
|
||||||
|
return missingFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define MAXSUFFIXSIZE 8
|
||||||
|
int FIO_decompressMultipleFilenames(const char** srcNamesTable, unsigned nbFiles,
|
||||||
|
const char* suffix,
|
||||||
|
const char* dictFileName)
|
||||||
|
{
|
||||||
|
unsigned u;
|
||||||
|
int skippedFiles = 0;
|
||||||
|
int missingFiles = 0;
|
||||||
|
char* dstFileName = (char*)malloc(FNSPACE);
|
||||||
|
size_t dfnSize = FNSPACE;
|
||||||
|
const size_t suffixSize = strlen(suffix);
|
||||||
|
dRess_t ress;
|
||||||
|
|
||||||
|
if (dstFileName==NULL) EXM_THROW(70, "not enough memory for dstFileName");
|
||||||
|
ress = FIO_createDResources(dictFileName);
|
||||||
|
|
||||||
|
for (u=0; u<nbFiles; u++)
|
||||||
|
{
|
||||||
|
const char* srcFileName = srcNamesTable[u];
|
||||||
|
size_t sfnSize = strlen(srcFileName);
|
||||||
|
const char* suffixPtr = srcFileName + sfnSize - suffixSize;
|
||||||
|
if (dfnSize <= sfnSize-suffixSize+1) { free(dstFileName); dfnSize = sfnSize + 20; dstFileName = (char*)malloc(dfnSize); if (dstFileName==NULL) EXM_THROW(71, "not enough memory for dstFileName"); }
|
||||||
|
if (sfnSize <= suffixSize || strcmp(suffixPtr, suffix) != 0)
|
||||||
|
{
|
||||||
|
DISPLAYLEVEL(1, "File extension doesn't match expected extension (%4s); will not process file: %s\n", suffix, srcFileName);
|
||||||
|
skippedFiles++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
memcpy(dstFileName, srcFileName, sfnSize - suffixSize);
|
||||||
|
dstFileName[sfnSize-suffixSize] = '\0';
|
||||||
|
|
||||||
|
missingFiles += FIO_decompressFile_extRess(ress, dstFileName, srcFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
FIO_freeDResources(ress);
|
||||||
|
free(dstFileName);
|
||||||
|
return missingFiles + skippedFiles;
|
||||||
|
}
|
||||||
|
@ -53,25 +53,30 @@ void FIO_setNotificationLevel(unsigned level);
|
|||||||
* Single File functions
|
* Single File functions
|
||||||
***************************************/
|
***************************************/
|
||||||
int FIO_compressFilename (const char* outfilename, const char* infilename, const char* dictFileName, int compressionLevel);
|
int FIO_compressFilename (const char* outfilename, const char* infilename, const char* dictFileName, int compressionLevel);
|
||||||
unsigned long long FIO_decompressFilename (const char* outfilename, const char* infilename, const char* dictFileName);
|
int FIO_decompressFilename (const char* outfilename, const char* infilename, const char* dictFileName);
|
||||||
/**
|
/**
|
||||||
FIO_compressFilename :
|
FIO_compressFilename :
|
||||||
@result : 0 == ok; 1 == pb with src file.
|
@result : 0 == ok; 1 == pb with src file.
|
||||||
|
|
||||||
FIO_decompressFilename :
|
FIO_decompressFilename :
|
||||||
@result : size of regenerated file
|
@result : 0 == ok; 1 == pb with src file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* *************************************
|
/* *************************************
|
||||||
* Multiple File functions
|
* Multiple File functions
|
||||||
***************************************/
|
***************************************/
|
||||||
int FIO_compressMultipleFilenames(const char** inFileNamesTable, unsigned nbFiles,
|
int FIO_compressMultipleFilenames(const char** srcNamesTable, unsigned nbFiles,
|
||||||
const char* suffix,
|
const char* suffix,
|
||||||
const char* dictFileName, int compressionLevel);
|
const char* dictFileName, int compressionLevel);
|
||||||
|
int FIO_decompressMultipleFilenames(const char** srcNamesTable, unsigned nbFiles,
|
||||||
|
const char* suffix,
|
||||||
|
const char* dictFileName);
|
||||||
/**
|
/**
|
||||||
FIO_compressMultipleFilenames :
|
FIO_compressMultipleFilenames :
|
||||||
@result : nb of missing files
|
@result : nb of missing files
|
||||||
|
FIO_decompressMultipleFilenames :
|
||||||
|
@result : nb of missing or skipped files
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,6 +49,19 @@ echo "*** dictionary tests *** "
|
|||||||
./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dv | md5sum > tmp2
|
./datagen -g1M | $ZSTD -D tmpDict | $ZSTD -D tmpDict -dv | md5sum > tmp2
|
||||||
diff -q tmp1 tmp2
|
diff -q tmp1 tmp2
|
||||||
|
|
||||||
|
echo "*** multiple files tests *** "
|
||||||
|
|
||||||
|
./datagen -s1 > tmp1 2> /dev/null
|
||||||
|
./datagen -s2 -g100K > tmp2 2> /dev/null
|
||||||
|
./datagen -s3 -g1M > tmp3 2> /dev/null
|
||||||
|
./zstd -f -m tmp*
|
||||||
|
ls -ls tmp*
|
||||||
|
rm tmp1 tmp2 tmp3
|
||||||
|
./zstd -df -m *.zst
|
||||||
|
ls -ls tmp*
|
||||||
|
./zstd -f -m tmp1 notHere tmp2 && die "missing file not detected!"
|
||||||
|
rm tmp*
|
||||||
|
|
||||||
echo "**** zstd round-trip tests **** "
|
echo "**** zstd round-trip tests **** "
|
||||||
|
|
||||||
roundTripTest
|
roundTripTest
|
||||||
|
@ -31,12 +31,21 @@ is equivalent to
|
|||||||
It is based on the \fBLZ77\fR family, with FSE & huff0 entropy stage.
|
It is based on the \fBLZ77\fR family, with FSE & huff0 entropy stage.
|
||||||
zstd offers compression speed > 200 MB/s per core.
|
zstd offers compression speed > 200 MB/s per core.
|
||||||
It also features a fast decoder, with speed > 500 MB/s per core.
|
It also features a fast decoder, with speed > 500 MB/s per core.
|
||||||
|
|
||||||
|
\fBzstd\fR command line is generally similar to gzip, but features the following differences :
|
||||||
|
- Original files are preserved
|
||||||
|
- By default, \fBzstd file1 file2\fR means : compress file1 \fBinto\fR file2.
|
||||||
|
Use \fB-m\fR command if you want : compress file1 into file1.zstd and file2 into file2.zst
|
||||||
|
- By default, when compressing files, \fBzstd\fR displays advancement notification and result summary.
|
||||||
|
Use \fB-q\fR to turn them off
|
||||||
|
|
||||||
|
|
||||||
\fBzstd\fR supports the following options :
|
\fBzstd\fR supports the following options :
|
||||||
|
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
.TP
|
.TP
|
||||||
.B \-1
|
.B \-#
|
||||||
fast compression (default)
|
# compression level [1-19](default:1)
|
||||||
.TP
|
.TP
|
||||||
.B \-d
|
.B \-d
|
||||||
decompression
|
decompression
|
||||||
@ -44,6 +53,14 @@ It also features a fast decoder, with speed > 500 MB/s per core.
|
|||||||
.B \-f
|
.B \-f
|
||||||
overwrite output without prompting
|
overwrite output without prompting
|
||||||
.TP
|
.TP
|
||||||
|
.BR \-m ", " --multiple
|
||||||
|
multiple files mode
|
||||||
|
In this mode, multiple files on the command line means compression or decompression of each named file
|
||||||
|
Notifications are also turned off by default
|
||||||
|
.TP
|
||||||
|
.B \-D
|
||||||
|
Use next file as dictionary content for compress / decompression
|
||||||
|
.TP
|
||||||
.BR \-h/\-H ", " --help
|
.BR \-h/\-H ", " --help
|
||||||
display help/long help and exit
|
display help/long help and exit
|
||||||
.TP
|
.TP
|
||||||
@ -53,20 +70,17 @@ It also features a fast decoder, with speed > 500 MB/s per core.
|
|||||||
.BR \-v ", " --verbose
|
.BR \-v ", " --verbose
|
||||||
verbose mode
|
verbose mode
|
||||||
.TP
|
.TP
|
||||||
.B \-q
|
.BR \-q ", " --quiet
|
||||||
suppress warnings; specify twice to suppress errors too
|
suppress warnings and notifications; specify twice to suppress errors too
|
||||||
.TP
|
.TP
|
||||||
.B \-c
|
.B \-c
|
||||||
force write to standard output, even if it is the console
|
force write to standard output, even if it is the console
|
||||||
.TP
|
.TP
|
||||||
.B \-t
|
|
||||||
test compressed file integrity
|
|
||||||
.TP
|
|
||||||
.B \-z
|
.B \-z
|
||||||
force compression
|
force compression
|
||||||
.TP
|
.TP
|
||||||
.B \-b
|
.B \-b#
|
||||||
benchmark file(s)
|
benchmark file(s) using compression level #
|
||||||
.TP
|
.TP
|
||||||
.B \-i#
|
.B \-i#
|
||||||
iteration loops [1-9](default : 3), benchmark mode only
|
iteration loops [1-9](default : 3), benchmark mode only
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
#ifndef ZSTD_NOBENCH
|
#ifndef ZSTD_NOBENCH
|
||||||
# include "bench.h" /* BMK_benchFiles, BMK_SetNbIterations */
|
# include "bench.h" /* BMK_benchFiles, BMK_SetNbIterations */
|
||||||
#endif
|
#endif
|
||||||
|
#include "zstd.h" /* ZSTD version numbers */
|
||||||
|
|
||||||
|
|
||||||
/**************************************
|
/**************************************
|
||||||
@ -72,7 +73,9 @@
|
|||||||
**************************************/
|
**************************************/
|
||||||
#define COMPRESSOR_NAME "zstd command line interface"
|
#define COMPRESSOR_NAME "zstd command line interface"
|
||||||
#ifndef ZSTD_VERSION
|
#ifndef ZSTD_VERSION
|
||||||
# define ZSTD_VERSION "v0.4.4"
|
# define QUOTE(str) #str
|
||||||
|
# define EXPAND_AND_QUOTE(str) QUOTE(str)
|
||||||
|
# define ZSTD_VERSION "v" EXPAND_AND_QUOTE(ZSTD_VERSION_MAJOR) "." EXPAND_AND_QUOTE(ZSTD_VERSION_MINOR) "." EXPAND_AND_QUOTE(ZSTD_VERSION_RELEASE)
|
||||||
#endif
|
#endif
|
||||||
#define AUTHOR "Yann Collet"
|
#define AUTHOR "Yann Collet"
|
||||||
#define WELCOME_MESSAGE "*** %s %i-bits %s, by %s (%s) ***\n", COMPRESSOR_NAME, (int)(sizeof(void*)*8), ZSTD_VERSION, AUTHOR, __DATE__
|
#define WELCOME_MESSAGE "*** %s %i-bits %s, by %s (%s) ***\n", COMPRESSOR_NAME, (int)(sizeof(void*)*8), ZSTD_VERSION, AUTHOR, __DATE__
|
||||||
@ -140,7 +143,6 @@ static int usage_advanced(const char* programName)
|
|||||||
DISPLAY( " -m : multiple input filenames mode");
|
DISPLAY( " -m : multiple input filenames mode");
|
||||||
DISPLAY( " -c : force write to standard output, even if it is the console\n");
|
DISPLAY( " -c : force write to standard output, even if it is the console\n");
|
||||||
DISPLAY( " -D file: use file content as Dictionary \n");
|
DISPLAY( " -D file: use file content as Dictionary \n");
|
||||||
//DISPLAY( " -t : test compressed file integrity\n");
|
|
||||||
#ifndef ZSTD_NOBENCH
|
#ifndef ZSTD_NOBENCH
|
||||||
DISPLAY( "Benchmark arguments :\n");
|
DISPLAY( "Benchmark arguments :\n");
|
||||||
DISPLAY( " -b# : benchmark file(s), using # compression level (default : 1) \n");
|
DISPLAY( " -b# : benchmark file(s), using # compression level (default : 1) \n");
|
||||||
@ -210,7 +212,9 @@ int main(int argCount, const char** argv)
|
|||||||
/* long commands (--long-word) */
|
/* long commands (--long-word) */
|
||||||
if (!strcmp(argument, "--version")) { displayOut=stdout; DISPLAY(WELCOME_MESSAGE); return 0; }
|
if (!strcmp(argument, "--version")) { displayOut=stdout; DISPLAY(WELCOME_MESSAGE); return 0; }
|
||||||
if (!strcmp(argument, "--help")) { displayOut=stdout; return usage_advanced(programName); }
|
if (!strcmp(argument, "--help")) { displayOut=stdout; return usage_advanced(programName); }
|
||||||
|
if (!strcmp(argument, "--multiple")) { multiple=1; continue; }
|
||||||
if (!strcmp(argument, "--verbose")) { displayLevel=4; continue; }
|
if (!strcmp(argument, "--verbose")) { displayLevel=4; continue; }
|
||||||
|
if (!strcmp(argument, "--quiet")) { displayLevel--; continue; }
|
||||||
|
|
||||||
/* Decode commands (note : aggregated commands are allowed) */
|
/* Decode commands (note : aggregated commands are allowed) */
|
||||||
if (argument[0]=='-')
|
if (argument[0]=='-')
|
||||||
@ -400,16 +404,27 @@ int main(int argCount, const char** argv)
|
|||||||
if (!strcmp(inFileName, stdinmark) && !strcmp(outFileName,stdoutmark) && (displayLevel==2)) displayLevel=1;
|
if (!strcmp(inFileName, stdinmark) && !strcmp(outFileName,stdoutmark) && (displayLevel==2)) displayLevel=1;
|
||||||
if (multiple && (displayLevel==2)) displayLevel=1;
|
if (multiple && (displayLevel==2)) displayLevel=1;
|
||||||
|
|
||||||
|
if ((!multiple) && (nbFiles>2))
|
||||||
|
{
|
||||||
|
DISPLAY("Too many files on the command line (%u > 2). Do you mean -m ? \n", nbFiles);
|
||||||
|
return nbFiles;
|
||||||
|
}
|
||||||
|
|
||||||
/* IO Stream/File */
|
/* IO Stream/File */
|
||||||
FIO_setNotificationLevel(displayLevel);
|
FIO_setNotificationLevel(displayLevel);
|
||||||
if (decode)
|
if (decode)
|
||||||
|
{
|
||||||
|
if (multiple)
|
||||||
|
operationResult = FIO_decompressMultipleFilenames(argv+fileNameStart, nbFiles, ZSTD_EXTENSION, dictFileName);
|
||||||
|
else
|
||||||
FIO_decompressFilename(outFileName, inFileName, dictFileName);
|
FIO_decompressFilename(outFileName, inFileName, dictFileName);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (multiple)
|
if (multiple)
|
||||||
operationResult = FIO_compressMultipleFilenames(argv+fileNameStart, nbFiles, ZSTD_EXTENSION, dictFileName, cLevel);
|
operationResult = FIO_compressMultipleFilenames(argv+fileNameStart, nbFiles, ZSTD_EXTENSION, dictFileName, cLevel);
|
||||||
else
|
else
|
||||||
FIO_compressFilename(outFileName, inFileName, dictFileName, cLevel);
|
operationResult = FIO_compressFilename(outFileName, inFileName, dictFileName, cLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
_end:
|
_end:
|
||||||
|
Reference in New Issue
Block a user