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

Function FIO_decompressLz4Frame

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

Source from the content-addressed store, hash-verified

2309
2310#ifdef ZSTD_LZ4DECOMPRESS
2311static unsigned long long
2312FIO_decompressLz4Frame(dRess_t* ress, FILE* srcFile,
2313 const FIO_prefs_t* const prefs,
2314 const char* srcFileName)
2315{
2316 unsigned long long filesize = 0;
2317 LZ4F_errorCode_t nextToLoad;
2318 LZ4F_decompressionContext_t dCtx;
2319 LZ4F_errorCode_t const errorCode = LZ4F_createDecompressionContext(&dCtx, LZ4F_VERSION);
2320 int decodingError = 0;
2321 unsigned storedSkips = 0;
2322
2323 if (LZ4F_isError(errorCode)) {
2324 DISPLAYLEVEL(1, "zstd: failed to create lz4 decompression context \n");
2325 return FIO_ERROR_FRAME_DECODING;
2326 }
2327
2328 /* Init feed with magic number (already consumed from FILE* sFile) */
2329 { size_t inSize = 4;
2330 size_t outSize= 0;
2331 MEM_writeLE32(ress->srcBuffer, LZ4_MAGICNUMBER);
2332 nextToLoad = LZ4F_decompress(dCtx, ress->dstBuffer, &outSize, ress->srcBuffer, &inSize, NULL);
2333 if (LZ4F_isError(nextToLoad)) {
2334 DISPLAYLEVEL(1, "zstd: %s: lz4 header error : %s \n",
2335 srcFileName, LZ4F_getErrorName(nextToLoad));
2336 LZ4F_freeDecompressionContext(dCtx);
2337 return FIO_ERROR_FRAME_DECODING;
2338 } }
2339
2340 /* Main Loop */
2341 for (;nextToLoad;) {
2342 size_t readSize;
2343 size_t pos = 0;
2344 size_t decodedBytes = ress->dstBufferSize;
2345
2346 /* Read input */
2347 if (nextToLoad > ress->srcBufferSize) nextToLoad = ress->srcBufferSize;
2348 readSize = fread(ress->srcBuffer, 1, nextToLoad, srcFile);
2349 if (!readSize) break; /* reached end of file or stream */
2350
2351 while ((pos < readSize) || (decodedBytes == ress->dstBufferSize)) { /* still to read, or still to flush */
2352 /* Decode Input (at least partially) */
2353 size_t remaining = readSize - pos;
2354 decodedBytes = ress->dstBufferSize;
2355 nextToLoad = LZ4F_decompress(dCtx, ress->dstBuffer, &decodedBytes, (char*)(ress->srcBuffer)+pos, &remaining, NULL);
2356 if (LZ4F_isError(nextToLoad)) {
2357 DISPLAYLEVEL(1, "zstd: %s: lz4 decompression error : %s \n",
2358 srcFileName, LZ4F_getErrorName(nextToLoad));
2359 decodingError = 1; nextToLoad = 0; break;
2360 }
2361 pos += remaining;
2362
2363 /* Write Block */
2364 if (decodedBytes) {
2365 storedSkips = FIO_fwriteSparse(ress->dstFile, ress->dstBuffer, decodedBytes, prefs, storedSkips);
2366 filesize += decodedBytes;
2367 DISPLAYUPDATE(2, "\rDecompressed : %u MB ", (unsigned)(filesize>>20));
2368 }

Callers 1

FIO_decompressFramesFunction · 0.85

Calls 3

FIO_fwriteSparseFunction · 0.85
FIO_fwriteSparseEndFunction · 0.85
MEM_writeLE32Function · 0.50

Tested by

no test coverage detected