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

Function FIO_decompressLzmaFrame

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

Source from the content-addressed store, hash-verified

2238
2239#ifdef ZSTD_LZMADECOMPRESS
2240static unsigned long long
2241FIO_decompressLzmaFrame(dRess_t* ress, FILE* srcFile,
2242 const FIO_prefs_t* const prefs,
2243 const char* srcFileName, int plain_lzma)
2244{
2245 unsigned long long outFileSize = 0;
2246 lzma_stream strm = LZMA_STREAM_INIT;
2247 lzma_action action = LZMA_RUN;
2248 lzma_ret initRet;
2249 int decodingError = 0;
2250 unsigned storedSkips = 0;
2251
2252 strm.next_in = 0;
2253 strm.avail_in = 0;
2254 if (plain_lzma) {
2255 initRet = lzma_alone_decoder(&strm, UINT64_MAX); /* LZMA */
2256 } else {
2257 initRet = lzma_stream_decoder(&strm, UINT64_MAX, 0); /* XZ */
2258 }
2259
2260 if (initRet != LZMA_OK) {
2261 DISPLAYLEVEL(1, "zstd: %s: %s error %d \n",
2262 plain_lzma ? "lzma_alone_decoder" : "lzma_stream_decoder",
2263 srcFileName, initRet);
2264 return FIO_ERROR_FRAME_DECODING;
2265 }
2266
2267 strm.next_out = (BYTE*)ress->dstBuffer;
2268 strm.avail_out = ress->dstBufferSize;
2269 strm.next_in = (BYTE const*)ress->srcBuffer;
2270 strm.avail_in = ress->srcBufferLoaded;
2271
2272 for ( ; ; ) {
2273 lzma_ret ret;
2274 if (strm.avail_in == 0) {
2275 ress->srcBufferLoaded = fread(ress->srcBuffer, 1, ress->srcBufferSize, srcFile);
2276 if (ress->srcBufferLoaded == 0) action = LZMA_FINISH;
2277 strm.next_in = (BYTE const*)ress->srcBuffer;
2278 strm.avail_in = ress->srcBufferLoaded;
2279 }
2280 ret = lzma_code(&strm, action);
2281
2282 if (ret == LZMA_BUF_ERROR) {
2283 DISPLAYLEVEL(1, "zstd: %s: premature lzma end \n", srcFileName);
2284 decodingError = 1; break;
2285 }
2286 if (ret != LZMA_OK && ret != LZMA_STREAM_END) {
2287 DISPLAYLEVEL(1, "zstd: %s: lzma_code decoding error %d \n",
2288 srcFileName, ret);
2289 decodingError = 1; break;
2290 }
2291 { size_t const decompBytes = ress->dstBufferSize - strm.avail_out;
2292 if (decompBytes) {
2293 storedSkips = FIO_fwriteSparse(ress->dstFile, ress->dstBuffer, decompBytes, prefs, storedSkips);
2294 outFileSize += decompBytes;
2295 strm.next_out = (BYTE*)ress->dstBuffer;
2296 strm.avail_out = ress->dstBufferSize;
2297 } }

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