LZ4IO_passThrough() doesn't need prefs

This commit is contained in:
Yann Collet 2020-11-13 21:47:17 -08:00
parent c8c3f8e62e
commit 8d37662e48

View File

@ -1102,25 +1102,30 @@ LZ4IO_decompressLZ4F(dRess_t ress,
} }
/* LZ4IO_passThrough:
* just output the same content as input, no decoding.
* This is a capability of zcat, and by extension lz4cat
* MNstore : contain the first MAGICNUMBER_SIZE bytes already read from finput
*/
#define PTSIZE (64 KB) #define PTSIZE (64 KB)
#define PTSIZET (PTSIZE / sizeof(size_t)) #define PTSIZET (PTSIZE / sizeof(size_t))
static unsigned long long static unsigned long long
LZ4IO_passThrough(LZ4IO_prefs_t* const prefs, LZ4IO_passThrough(FILE* finput, FILE* foutput,
FILE* finput, FILE* foutput, unsigned char MNstore[MAGICNUMBER_SIZE],
unsigned char MNstore[MAGICNUMBER_SIZE]) int sparseFileSupport)
{ {
size_t buffer[PTSIZET]; size_t buffer[PTSIZET];
size_t readBytes = 1; size_t readBytes = 1;
unsigned long long total = MAGICNUMBER_SIZE; unsigned long long total = MAGICNUMBER_SIZE;
unsigned storedSkips = 0; unsigned storedSkips = 0;
size_t const sizeCheck = fwrite(MNstore, 1, MAGICNUMBER_SIZE, foutput); if (fwrite(MNstore, 1, MAGICNUMBER_SIZE, foutput) != MAGICNUMBER_SIZE) {
if (sizeCheck != MAGICNUMBER_SIZE) EXM_THROW(50, "Pass-through write error"); EXM_THROW(50, "Pass-through write error");
}
while (readBytes) { while (readBytes) {
readBytes = fread(buffer, 1, PTSIZE, finput); readBytes = fread(buffer, 1, sizeof(buffer), finput);
total += readBytes; total += readBytes;
storedSkips = LZ4IO_fwriteSparse(foutput, buffer, readBytes, prefs->sparseFileSupport, storedSkips); storedSkips = LZ4IO_fwriteSparse(foutput, buffer, readBytes, sparseFileSupport, storedSkips);
} }
if (ferror(finput)) EXM_THROW(51, "Read Error"); if (ferror(finput)) EXM_THROW(51, "Read Error");
@ -1198,7 +1203,7 @@ selectDecoder(LZ4IO_prefs_t* const prefs,
/* Wrong magic number at the beginning of 1st stream */ /* Wrong magic number at the beginning of 1st stream */
if (!prefs->testMode && prefs->overwrite && prefs->passThrough) { if (!prefs->testMode && prefs->overwrite && prefs->passThrough) {
nbFrames = 0; nbFrames = 0;
return LZ4IO_passThrough(prefs, finput, foutput, MNstore); return LZ4IO_passThrough(finput, foutput, MNstore, prefs->sparseFileSupport);
} }
EXM_THROW(44,"Unrecognized header : file cannot be decoded"); EXM_THROW(44,"Unrecognized header : file cannot be decoded");
} }