static RTEXITCODE gzipDecompress(RTVFSIOSTREAM hVfsIn, RTVFSIOSTREAM hVfsOut) { RTEXITCODE rcExit; RTVFSIOSTREAM hVfsGunzip; int rc = RTZipGzipDecompressIoStream(hVfsIn, 0 /*fFlags*/, &hVfsGunzip); if (RT_SUCCESS(rc)) { rcExit = gzipPush(hVfsGunzip, hVfsOut); RTVfsIoStrmRelease(hVfsGunzip); } else rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "RTZipGzipDecompressIoStream failed: %Rrc", rc); return rcExit; }
/** * Pushes the bytes from the input to the output stream, flushes the output * stream and closes both of them. * * On failure, we will delete the output file, if it's a file. The input file * may be deleted, if we're not told to keep it (--keep, --to-stdout). * * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE. * @param phVfsSrc The input stream. Set to NIL if closed. * @param pOpts The options. * @param phVfsDst The output stream. Set to NIL if closed. */ static RTEXITCODE gzipPushFlushAndClose(PRTVFSIOSTREAM phVfsSrc, PCRTGZIPCMDOPTS pOpts, PRTVFSIOSTREAM phVfsDst) { /* * Push bytes, flush and close the streams. */ RTEXITCODE rcExit = gzipPush(*phVfsSrc, *phVfsDst); RTVfsIoStrmRelease(*phVfsSrc); *phVfsSrc = NIL_RTVFSIOSTREAM; int rc = RTVfsIoStrmFlush(*phVfsDst); if (RT_FAILURE(rc) && rc != VERR_INVALID_PARAMETER) rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to flush the output file: %Rrc", rc); RTVfsIoStrmRelease(*phVfsDst); *phVfsDst = NIL_RTVFSIOSTREAM; /* * Do the cleaning up, if needed. Remove the input file, if that's the * desire of the user, or remove the output file on failure. */ if (!pOpts->fStdOut) { if (rcExit == RTEXITCODE_SUCCESS) { if (!pOpts->fKeep) { rc = RTFileDelete(pOpts->pszInput); if (RT_FAILURE(rc)) rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to delete '%s': %Rrc", pOpts->pszInput, rc); } } else { rc = RTFileDelete(pOpts->szOutput); if (RT_FAILURE(rc)) RTMsgError("Failed to delete '%s': %Rrc", pOpts->szOutput, rc); } } return rcExit; }