improved FIO_decompressGzFrame
This commit is contained in:
parent
8489f184f6
commit
3c69760275
@ -652,7 +652,6 @@ static unsigned FIO_passThrough(FILE* foutput, FILE* finput, void* buffer, size_
|
|||||||
#ifdef ZSTD_GZDECOMPRESS
|
#ifdef ZSTD_GZDECOMPRESS
|
||||||
static unsigned long long FIO_decompressGzFrame(dRess_t ress, FILE* srcFile, const char* srcFileName, size_t alreadyLoaded)
|
static unsigned long long FIO_decompressGzFrame(dRess_t ress, FILE* srcFile, const char* srcFileName, size_t alreadyLoaded)
|
||||||
{
|
{
|
||||||
unsigned char* headBuf = (unsigned char*)ress.srcBuffer;
|
|
||||||
unsigned long long outFileSize = 0;
|
unsigned long long outFileSize = 0;
|
||||||
z_stream strm;
|
z_stream strm;
|
||||||
|
|
||||||
@ -667,15 +666,15 @@ static unsigned long long FIO_decompressGzFrame(dRess_t ress, FILE* srcFile, con
|
|||||||
strm.avail_out = ress.dstBufferSize;
|
strm.avail_out = ress.dstBufferSize;
|
||||||
|
|
||||||
for ( ; ; ) {
|
for ( ; ; ) {
|
||||||
unsigned char in[1];
|
|
||||||
if (alreadyLoaded) {
|
if (alreadyLoaded) {
|
||||||
alreadyLoaded--;
|
strm.avail_in = alreadyLoaded;
|
||||||
in[0] = *headBuf++;
|
strm.next_in = (z_const unsigned char*)ress.srcBuffer;
|
||||||
|
alreadyLoaded = 0;
|
||||||
} else {
|
} else {
|
||||||
if (fread(in, 1, 1, srcFile) == 0) break;
|
if (fread(ress.srcBuffer, 1, 1/*ress.srcBufferSize*/, srcFile) == 0) break;
|
||||||
|
strm.next_in = (z_const unsigned char*)ress.srcBuffer;
|
||||||
|
strm.avail_in = 1;
|
||||||
}
|
}
|
||||||
strm.next_in = in;
|
|
||||||
strm.avail_in = 1;
|
|
||||||
{ int const ret = inflate(&strm, Z_NO_FLUSH);
|
{ int const ret = inflate(&strm, Z_NO_FLUSH);
|
||||||
if (ret == Z_STREAM_END) break;
|
if (ret == Z_STREAM_END) break;
|
||||||
if (ret != Z_OK) { DISPLAY("zstd: %s: inflate error %d \n", srcFileName, ret); return 0; }
|
if (ret != Z_OK) { DISPLAY("zstd: %s: inflate error %d \n", srcFileName, ret); return 0; }
|
||||||
@ -726,11 +725,11 @@ static int FIO_decompressSrcFile(dRess_t ress, const char* dstFileName, const ch
|
|||||||
}
|
}
|
||||||
readSomething = 1; /* there is at least >= 4 bytes in srcFile */
|
readSomething = 1; /* there is at least >= 4 bytes in srcFile */
|
||||||
if (sizeCheck != toRead) { DISPLAY("zstd: %s: unknown header \n", srcFileName); fclose(srcFile); return 1; } /* srcFileName is empty */
|
if (sizeCheck != toRead) { DISPLAY("zstd: %s: unknown header \n", srcFileName); fclose(srcFile); return 1; } /* srcFileName is empty */
|
||||||
printf("buf[0]=%d buf[1]=%d toRead=%d\n", buf[0], buf[1], (int)toRead);
|
|
||||||
if (buf[0] == 31 && buf[1] == 139) { /* gz header */
|
if (buf[0] == 31 && buf[1] == 139) { /* gz header */
|
||||||
#ifdef ZSTD_GZDECOMPRESS
|
#ifdef ZSTD_GZDECOMPRESS
|
||||||
unsigned long long const result = FIO_decompressGzFrame(ress, srcFile, srcFileName, toRead);
|
unsigned long long const result = FIO_decompressGzFrame(ress, srcFile, srcFileName, toRead);
|
||||||
if (result == 0) return 1;
|
if (result == 0) return 1;
|
||||||
|
printf("gzip=%d\n", (int)result);
|
||||||
filesize += result;
|
filesize += result;
|
||||||
#else
|
#else
|
||||||
DISPLAYLEVEL(1, "zstd: %s: gzip file cannot be uncompressed (zstd compiled without ZSTD_GZDECOMPRESS) -- ignored \n", srcFileName);
|
DISPLAYLEVEL(1, "zstd: %s: gzip file cannot be uncompressed (zstd compiled without ZSTD_GZDECOMPRESS) -- ignored \n", srcFileName);
|
||||||
@ -740,6 +739,7 @@ static int FIO_decompressSrcFile(dRess_t ress, const char* dstFileName, const ch
|
|||||||
if (!ZSTD_isFrame(ress.srcBuffer, toRead)) {
|
if (!ZSTD_isFrame(ress.srcBuffer, toRead)) {
|
||||||
if ((g_overwrite) && !strcmp (dstFileName, stdoutmark)) { /* pass-through mode */
|
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);
|
||||||
|
printf("pass-through=%d\n", (int)result);
|
||||||
if (fclose(srcFile)) EXM_THROW(32, "zstd: %s close error", srcFileName); /* error should never happen */
|
if (fclose(srcFile)) EXM_THROW(32, "zstd: %s close error", srcFileName); /* error should never happen */
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
@ -748,6 +748,7 @@ static int FIO_decompressSrcFile(dRess_t ress, const char* dstFileName, const ch
|
|||||||
return 1;
|
return 1;
|
||||||
} }
|
} }
|
||||||
filesize += FIO_decompressFrame(ress, srcFile, toRead, filesize);
|
filesize += FIO_decompressFrame(ress, srcFile, toRead, filesize);
|
||||||
|
printf("zstd filesize=%d\n", (int)filesize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user