MCPcopy Create free account
hub / github.com/F-Stack/f-stack / FIO_decompressGzFrame

Function FIO_decompressGzFrame

freebsd/contrib/zstd/programs/fileio.c:2172–2235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2170
2171#ifdef ZSTD_GZDECOMPRESS
2172static unsigned long long
2173FIO_decompressGzFrame(dRess_t* ress, FILE* srcFile,
2174 const FIO_prefs_t* const prefs,
2175 const char* srcFileName)
2176{
2177 unsigned long long outFileSize = 0;
2178 z_stream strm;
2179 int flush = Z_NO_FLUSH;
2180 int decodingError = 0;
2181 unsigned storedSkips = 0;
2182
2183 strm.zalloc = Z_NULL;
2184 strm.zfree = Z_NULL;
2185 strm.opaque = Z_NULL;
2186 strm.next_in = 0;
2187 strm.avail_in = 0;
2188 /* see http://www.zlib.net/manual.html */
2189 if (inflateInit2(&strm, 15 /* maxWindowLogSize */ + 16 /* gzip only */) != Z_OK)
2190 return FIO_ERROR_FRAME_DECODING;
2191
2192 strm.next_out = (Bytef*)ress->dstBuffer;
2193 strm.avail_out = (uInt)ress->dstBufferSize;
2194 strm.avail_in = (uInt)ress->srcBufferLoaded;
2195 strm.next_in = (z_const unsigned char*)ress->srcBuffer;
2196
2197 for ( ; ; ) {
2198 int ret;
2199 if (strm.avail_in == 0) {
2200 ress->srcBufferLoaded = fread(ress->srcBuffer, 1, ress->srcBufferSize, srcFile);
2201 if (ress->srcBufferLoaded == 0) flush = Z_FINISH;
2202 strm.next_in = (z_const unsigned char*)ress->srcBuffer;
2203 strm.avail_in = (uInt)ress->srcBufferLoaded;
2204 }
2205 ret = inflate(&strm, flush);
2206 if (ret == Z_BUF_ERROR) {
2207 DISPLAYLEVEL(1, "zstd: %s: premature gz end \n", srcFileName);
2208 decodingError = 1; break;
2209 }
2210 if (ret != Z_OK && ret != Z_STREAM_END) {
2211 DISPLAYLEVEL(1, "zstd: %s: inflate error %d \n", srcFileName, ret);
2212 decodingError = 1; break;
2213 }
2214 { size_t const decompBytes = ress->dstBufferSize - strm.avail_out;
2215 if (decompBytes) {
2216 storedSkips = FIO_fwriteSparse(ress->dstFile, ress->dstBuffer, decompBytes, prefs, storedSkips);
2217 outFileSize += decompBytes;
2218 strm.next_out = (Bytef*)ress->dstBuffer;
2219 strm.avail_out = (uInt)ress->dstBufferSize;
2220 }
2221 }
2222 if (ret == Z_STREAM_END) break;
2223 }
2224
2225 if (strm.avail_in > 0)
2226 memmove(ress->srcBuffer, strm.next_in, strm.avail_in);
2227 ress->srcBufferLoaded = strm.avail_in;
2228 if ( (inflateEnd(&strm) != Z_OK) /* release resources ; error detected */
2229 && (decodingError==0) ) {

Callers 1

FIO_decompressFramesFunction · 0.85

Calls 3

FIO_fwriteSparseFunction · 0.85
FIO_fwriteSparseEndFunction · 0.85
memmoveFunction · 0.50

Tested by

no test coverage detected