FIO_decompressFrames() : * Find and decode frames inside srcFile * srcFile presumed opened and valid * @return : 0 : OK * 1 : error */
| 2398 | * 1 : error |
| 2399 | */ |
| 2400 | static int FIO_decompressFrames(FIO_ctx_t* const fCtx, |
| 2401 | dRess_t ress, FILE* srcFile, |
| 2402 | const FIO_prefs_t* const prefs, |
| 2403 | const char* dstFileName, const char* srcFileName) |
| 2404 | { |
| 2405 | unsigned readSomething = 0; |
| 2406 | unsigned long long filesize = 0; |
| 2407 | assert(srcFile != NULL); |
| 2408 | |
| 2409 | /* for each frame */ |
| 2410 | for ( ; ; ) { |
| 2411 | /* check magic number -> version */ |
| 2412 | size_t const toRead = 4; |
| 2413 | const BYTE* const buf = (const BYTE*)ress.srcBuffer; |
| 2414 | if (ress.srcBufferLoaded < toRead) /* load up to 4 bytes for header */ |
| 2415 | ress.srcBufferLoaded += fread((char*)ress.srcBuffer + ress.srcBufferLoaded, |
| 2416 | (size_t)1, toRead - ress.srcBufferLoaded, srcFile); |
| 2417 | if (ress.srcBufferLoaded==0) { |
| 2418 | if (readSomething==0) { /* srcFile is empty (which is invalid) */ |
| 2419 | DISPLAYLEVEL(1, "zstd: %s: unexpected end of file \n", srcFileName); |
| 2420 | return 1; |
| 2421 | } /* else, just reached frame boundary */ |
| 2422 | break; /* no more input */ |
| 2423 | } |
| 2424 | readSomething = 1; /* there is at least 1 byte in srcFile */ |
| 2425 | if (ress.srcBufferLoaded < toRead) { |
| 2426 | DISPLAYLEVEL(1, "zstd: %s: unknown header \n", srcFileName); |
| 2427 | return 1; |
| 2428 | } |
| 2429 | if (ZSTD_isFrame(buf, ress.srcBufferLoaded)) { |
| 2430 | unsigned long long const frameSize = FIO_decompressZstdFrame(fCtx, &ress, srcFile, prefs, srcFileName, filesize); |
| 2431 | if (frameSize == FIO_ERROR_FRAME_DECODING) return 1; |
| 2432 | filesize += frameSize; |
| 2433 | } else if (buf[0] == 31 && buf[1] == 139) { /* gz magic number */ |
| 2434 | #ifdef ZSTD_GZDECOMPRESS |
| 2435 | unsigned long long const frameSize = FIO_decompressGzFrame(&ress, srcFile, prefs, srcFileName); |
| 2436 | if (frameSize == FIO_ERROR_FRAME_DECODING) return 1; |
| 2437 | filesize += frameSize; |
| 2438 | #else |
| 2439 | DISPLAYLEVEL(1, "zstd: %s: gzip file cannot be uncompressed (zstd compiled without HAVE_ZLIB) -- ignored \n", srcFileName); |
| 2440 | return 1; |
| 2441 | #endif |
| 2442 | } else if ((buf[0] == 0xFD && buf[1] == 0x37) /* xz magic number */ |
| 2443 | || (buf[0] == 0x5D && buf[1] == 0x00)) { /* lzma header (no magic number) */ |
| 2444 | #ifdef ZSTD_LZMADECOMPRESS |
| 2445 | unsigned long long const frameSize = FIO_decompressLzmaFrame(&ress, srcFile, prefs, srcFileName, buf[0] != 0xFD); |
| 2446 | if (frameSize == FIO_ERROR_FRAME_DECODING) return 1; |
| 2447 | filesize += frameSize; |
| 2448 | #else |
| 2449 | DISPLAYLEVEL(1, "zstd: %s: xz/lzma file cannot be uncompressed (zstd compiled without HAVE_LZMA) -- ignored \n", srcFileName); |
| 2450 | return 1; |
| 2451 | #endif |
| 2452 | } else if (MEM_readLE32(buf) == LZ4_MAGICNUMBER) { |
| 2453 | #ifdef ZSTD_LZ4DECOMPRESS |
| 2454 | unsigned long long const frameSize = FIO_decompressLz4Frame(&ress, srcFile, prefs, srcFileName); |
| 2455 | if (frameSize == FIO_ERROR_FRAME_DECODING) return 1; |
| 2456 | filesize += frameSize; |
| 2457 | #else |
no test coverage detected