Index: trunk/src/VBox/Runtime/common/misc/tar.cpp
===================================================================
--- trunk/src/VBox/Runtime/common/misc/tar.cpp	(revision 33804)
+++ 	(revision )
@@ -1,1645 +1,0 @@
-/* $Id$ */
-/** @file
- * IPRT - Tar archive I/O.
- */
-
-/*
- * Copyright (C) 2009-2010 Oracle Corporation
- *
- * This file is part of VirtualBox Open Source Edition (OSE), as
- * available from http://www.virtualbox.org. This file is free software;
- * you can redistribute it and/or modify it under the terms of the GNU
- * General Public License (GPL) as published by the Free Software
- * Foundation, in version 2 as it comes in the "COPYING" file of the
- * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
- * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
- *
- * The contents of this file may alternatively be used under the terms
- * of the Common Development and Distribution License Version 1.0
- * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
- * VirtualBox OSE distribution, in which case the provisions of the
- * CDDL are applicable instead of those of the GPL.
- *
- * You may elect to license modified versions of this file under the
- * terms and conditions of either the GPL or the CDDL or both.
- */
-
-
-/******************************************************************************
- *   Header Files                                                             *
- ******************************************************************************/
-#include "internal/iprt.h"
-#include "internal/magics.h"
-#include <iprt/tar.h>
-
-#include <iprt/asm.h>
-#include <iprt/assert.h>
-#include <iprt/err.h>
-#include <iprt/file.h>
-#include <iprt/mem.h>
-#include <iprt/path.h>
-#include <iprt/string.h>
-
-
-/******************************************************************************
- *   Structures and Typedefs                                                  *
- ******************************************************************************/
-
-/** @name RTTARRECORD::h::linkflag
- * @{  */
-#define LF_OLDNORMAL '\0' /**< Normal disk file, Unix compatible */
-#define LF_NORMAL    '0'  /**< Normal disk file */
-#define LF_LINK      '1'  /**< Link to previously dumped file */
-#define LF_SYMLINK   '2'  /**< Symbolic link */
-#define LF_CHR       '3'  /**< Character special file */
-#define LF_BLK       '4'  /**< Block special file */
-#define LF_DIR       '5'  /**< Directory */
-#define LF_FIFO      '6'  /**< FIFO special file */
-#define LF_CONTIG    '7'  /**< Contiguous file */
-/** @} */
-
-/**
- * A tar file header.
- */
-typedef union RTTARRECORD
-{
-    char   d[512];
-    struct h
-    {
-        char name[100];
-        char mode[8];
-        char uid[8];
-        char gid[8];
-        char size[12];
-        char mtime[12];
-        char chksum[8];
-        char linkflag;
-        char linkname[100];
-        char magic[8];
-        char uname[32];
-        char gname[32];
-        char devmajor[8];
-        char devminor[8];
-    } h;
-} RTTARRECORD;
-AssertCompileSize(RTTARRECORD, 512);
-AssertCompileMemberOffset(RTTARRECORD, h.size, 100+8*3);
-/** Pointer to a tar file header. */
-typedef RTTARRECORD *PRTTARRECORD;
-
-
-#if 0 /* not currently used */
-typedef struct RTTARFILELIST
-{
-    char *pszFilename;
-    RTTARFILELIST *pNext;
-} RTTARFILELIST;
-typedef RTTARFILELIST *PRTTARFILELIST;
-#endif
-
-/** Pointer to a tar file handle. */
-typedef struct RTTARFILEINTERNAL *PRTTARFILEINTERNAL;
-
-/**
- * The internal data of a tar handle.
- */
-typedef struct RTTARINTERNAL
-{
-    /** The magic (RTTAR_MAGIC). */
-    uint32_t            u32Magic;
-    /** The handle to the tar file. */
-    RTFILE              hTarFile;
-    /** The open mode for hTarFile. */
-    uint32_t            fOpenMode;
-    /** Whether a file within the archive is currently open for writing.
-     * Only one can be open.  */
-    bool                fFileOpenForWrite;
-    /** Whether operating in stream mode. */
-    bool                fStreamMode;
-    /** The file cache of one file.  */
-    PRTTARFILEINTERNAL  pFileCache;
-} RTTARINTERNAL;
-/** Pointer to a the internal data of a tar handle.  */
-typedef RTTARINTERNAL* PRTTARINTERNAL;
-
-/**
- * The internal data of a file within a tar file.
- */
-typedef struct RTTARFILEINTERNAL
-{
-    /** The magic (RTTARFILE_MAGIC). */
-    uint32_t        u32Magic;
-    /** Pointer to back to the tar file. */
-    PRTTARINTERNAL  pTar;
-    /** The name of the file. */
-    char           *pszFilename;
-    /** The offset into the archive where the file header starts. */
-    uint64_t        offStart;
-    /** The size of the file. */
-    uint64_t        cbSize;
-    /** The size set by RTTarFileSetSize(). */
-    uint64_t        cbSetSize;
-    /** The current offset within this file. */
-    uint64_t        offCurrent;
-    /** The open mode. */
-    uint32_t        fOpenMode;
-} RTTARFILEINTERNAL;
-/** Pointer to the internal data of a tar file.  */
-typedef RTTARFILEINTERNAL *PRTTARFILEINTERNAL;
-
-
-/******************************************************************************
- *   Defined Constants And Macros                                             *
- ******************************************************************************/
-
-/** Validates a handle and returns VERR_INVALID_HANDLE if not valid. */
-/* RTTAR */
-#define RTTAR_VALID_RETURN_RC(hHandle, rc) \
-    do { \
-        AssertPtrReturn((hHandle), (rc)); \
-        AssertReturn((hHandle)->u32Magic == RTTAR_MAGIC, (rc)); \
-    } while (0)
-/* RTTARFILE */
-#define RTTARFILE_VALID_RETURN_RC(hHandle, rc) \
-    do { \
-        AssertPtrReturn((hHandle), (rc)); \
-        AssertReturn((hHandle)->u32Magic == RTTARFILE_MAGIC, (rc)); \
-    } while (0)
-
-/** Validates a handle and returns VERR_INVALID_HANDLE if not valid. */
-/* RTTAR */
-#define RTTAR_VALID_RETURN(hHandle) RTTAR_VALID_RETURN_RC((hHandle), VERR_INVALID_HANDLE)
-/* RTTARFILE */
-#define RTTARFILE_VALID_RETURN(hHandle) RTTARFILE_VALID_RETURN_RC((hHandle), VERR_INVALID_HANDLE)
-
-/** Validates a handle and returns (void) if not valid. */
-/* RTTAR */
-#define RTTAR_VALID_RETURN_VOID(hHandle) \
-    do { \
-        AssertPtrReturnVoid(hHandle); \
-        AssertReturnVoid((hHandle)->u32Magic == RTTAR_MAGIC); \
-    } while (0)
-/* RTTARFILE */
-#define RTTARFILE_VALID_RETURN_VOID(hHandle) \
-    do { \
-        AssertPtrReturnVoid(hHandle); \
-        AssertReturnVoid((hHandle)->u32Magic == RTTARFILE_MAGIC); \
-    } while (0)
-
-
-/******************************************************************************
- *   Internal Functions                                                       *
- ******************************************************************************/
-
-DECLINLINE(int) rtTarCalcChkSum(PRTTARRECORD pRecord, uint32_t *pChkSum)
-{
-    uint32_t check = 0;
-    uint32_t zero = 0;
-    for (size_t i = 0; i < sizeof(RTTARRECORD); ++i)
-    {
-        /* Calculate the sum of every byte from the header. The checksum field
-         * itself is counted as all blanks. */
-        if (   i <  RT_UOFFSETOF(RTTARRECORD, h.chksum)
-            || i >= RT_UOFFSETOF(RTTARRECORD, h.linkflag))
-            check += pRecord->d[i];
-        else
-            check += ' ';
-        /* Additional check if all fields are zero, which indicate EOF. */
-        zero += pRecord->d[i];
-    }
-
-    /* EOF? */
-    if (!zero)
-        return VERR_TAR_END_OF_FILE;
-
-    *pChkSum = check;
-    return VINF_SUCCESS;
-}
-
-DECLINLINE(int) rtTarReadHeaderRecord(RTFILE hFile, PRTTARRECORD pRecord)
-{
-    int rc = RTFileRead(hFile, pRecord, sizeof(RTTARRECORD), NULL);
-    /* Check for EOF. EOF is valid in this case, cause it indicates no more
-     * data in the tar archive. */
-    if (rc == VERR_EOF)
-        return VERR_TAR_END_OF_FILE;
-    /* Report any other errors */
-    else if (RT_FAILURE(rc))
-        return rc;
-
-    /* Check for data integrity & an EOF record */
-    uint32_t check = 0;
-    rc = rtTarCalcChkSum(pRecord, &check);
-    /* EOF? */
-    if (RT_FAILURE(rc))
-        return rc;
-
-    /* Verify the checksum */
-    uint32_t sum;
-    rc = RTStrToUInt32Full(pRecord->h.chksum, 8, &sum);
-    if (RT_SUCCESS(rc) && sum == check)
-    {
-        /* Make sure the strings are zero terminated. */
-        pRecord->h.name[sizeof(pRecord->h.name) - 1]         = 0;
-        pRecord->h.linkname[sizeof(pRecord->h.linkname) - 1] = 0;
-        pRecord->h.magic[sizeof(pRecord->h.magic) - 1]       = 0;
-        pRecord->h.uname[sizeof(pRecord->h.uname) - 1]       = 0;
-        pRecord->h.gname[sizeof(pRecord->h.gname) - 1]       = 0;
-    }
-    else
-        rc = VERR_TAR_CHKSUM_MISMATCH;
-
-    return rc;
-}
-
-DECLINLINE(int) rtTarCreateHeaderRecord(PRTTARRECORD pRecord, const char *pszSrcName, uint64_t cbSize,
-                                        RTUID uid, RTGID gid, RTFMODE fmode, int64_t mtime)
-{
-    /** @todo check for field overflows. */
-    /* Fill the header record */
-//    RT_ZERO(pRecord);
-    RTStrPrintf(pRecord->h.name,  sizeof(pRecord->h.name),  "%s",     pszSrcName);
-    RTStrPrintf(pRecord->h.mode,  sizeof(pRecord->h.mode),  "%0.7o",  fmode);
-    RTStrPrintf(pRecord->h.uid,   sizeof(pRecord->h.uid),   "%0.7o",  uid);
-    RTStrPrintf(pRecord->h.gid,   sizeof(pRecord->h.gid),   "%0.7o",  gid);
-    RTStrPrintf(pRecord->h.size,  sizeof(pRecord->h.size),  "%0.11o", cbSize);
-    RTStrPrintf(pRecord->h.mtime, sizeof(pRecord->h.mtime), "%0.11o", mtime);
-    RTStrPrintf(pRecord->h.magic, sizeof(pRecord->h.magic), "ustar  ");
-    RTStrPrintf(pRecord->h.uname, sizeof(pRecord->h.uname), "someone");
-    RTStrPrintf(pRecord->h.gname, sizeof(pRecord->h.gname), "someone");
-    pRecord->h.linkflag = LF_NORMAL;
-
-    /* Create the checksum out of the new header */
-    uint32_t uChkSum = 0;
-    int rc = rtTarCalcChkSum(pRecord, &uChkSum);
-    if (RT_FAILURE(rc))
-        return rc;
-    /* Format the checksum */
-    RTStrPrintf(pRecord->h.chksum, sizeof(pRecord->h.chksum), "%0.7o", uChkSum);
-
-    return VINF_SUCCESS;
-}
-
-DECLINLINE(void *) rtTarMemTmpAlloc(size_t *pcbSize)
-{
-    *pcbSize = 0;
-    /* Allocate a reasonably large buffer, fall back on a tiny one.
-     * Note: has to be 512 byte aligned and >= 512 byte. */
-    size_t cbTmp = _1M;
-    void *pvTmp = RTMemTmpAlloc(cbTmp);
-    if (!pvTmp)
-    {
-        cbTmp = sizeof(RTTARRECORD);
-        pvTmp = RTMemTmpAlloc(cbTmp);
-    }
-    *pcbSize = cbTmp;
-    return pvTmp;
-}
-
-DECLINLINE(int) rtTarAppendZeros(RTTARFILE hFile, uint64_t cbSize)
-{
-    /* Allocate a temporary buffer for copying the tar content in blocks. */
-    size_t cbTmp = 0;
-    void *pvTmp = rtTarMemTmpAlloc(&cbTmp);
-    if (!pvTmp)
-        return VERR_NO_MEMORY;
-    RT_BZERO(pvTmp, cbTmp);
-
-    int rc = VINF_SUCCESS;
-    uint64_t cbAllWritten = 0;
-    size_t cbWritten = 0;
-    for (;;)
-    {
-        if (cbAllWritten >= cbSize)
-            break;
-        size_t cbToWrite = RT_MIN(cbSize - cbAllWritten, cbTmp);
-        rc = RTTarFileWrite(hFile, pvTmp, cbToWrite, &cbWritten);
-        if (RT_FAILURE(rc))
-            break;
-        cbAllWritten += cbWritten;
-    }
-
-    RTMemTmpFree(pvTmp);
-
-    return rc;
-}
-
-DECLINLINE(PRTTARFILEINTERNAL) rtCreateTarFileInternal(PRTTARINTERNAL pInt, const char *pszFilename, uint32_t fOpen)
-{
-    PRTTARFILEINTERNAL pFileInt = (PRTTARFILEINTERNAL)RTMemAllocZ(sizeof(RTTARFILEINTERNAL));
-    if (!pFileInt)
-        return NULL;
-
-    pFileInt->u32Magic = RTTARFILE_MAGIC;
-    pFileInt->pTar = pInt;
-    pFileInt->fOpenMode = fOpen;
-    pFileInt->pszFilename = RTStrDup(pszFilename);
-    if (!pFileInt->pszFilename)
-    {
-        RTMemFree(pFileInt);
-        return NULL;
-    }
-
-    return pFileInt;
-}
-
-DECLINLINE(PRTTARFILEINTERNAL) rtCopyTarFileInternal(PRTTARFILEINTERNAL pInt)
-{
-    PRTTARFILEINTERNAL pNewInt = (PRTTARFILEINTERNAL)RTMemAllocZ(sizeof(RTTARFILEINTERNAL));
-    if (!pNewInt)
-        return NULL;
-
-    memcpy(pNewInt, pInt, sizeof(RTTARFILEINTERNAL));
-    pNewInt->pszFilename = RTStrDup(pInt->pszFilename);
-    if (!pNewInt->pszFilename)
-    {
-        RTMemFree(pNewInt);
-        return NULL;
-    }
-
-    return pNewInt;
-}
-
-DECLINLINE(void) rtDeleteTarFileInternal(PRTTARFILEINTERNAL pInt)
-{
-    if (pInt)
-    {
-        if (pInt->pszFilename)
-            RTStrFree(pInt->pszFilename);
-        pInt->u32Magic = RTTARFILE_MAGIC_DEAD;
-        RTMemFree(pInt);
-    }
-}
-
-static int rtTarExtractFileToFile(RTTARFILE hFile, const char *pszTargetName, const uint64_t cbOverallSize, uint64_t &cbOverallWritten, PFNRTPROGRESS pfnProgressCallback, void *pvUser)
-{
-    /* Open the target file */
-    RTFILE hNewFile;
-    int rc = RTFileOpen(&hNewFile, pszTargetName, RTFILE_O_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_WRITE);
-    if (RT_FAILURE(rc))
-        return rc;
-
-    void *pvTmp = NULL;
-    do
-    {
-        /* Allocate a temporary buffer for reading the tar content in blocks. */
-        size_t cbTmp = 0;
-        pvTmp = rtTarMemTmpAlloc(&cbTmp);
-        if (!pvTmp)
-        {
-            rc = VERR_NO_MEMORY;
-            break;
-        }
-
-        /* Get the size of the source file */
-        uint64_t cbToCopy = 0;
-        rc = RTTarFileGetSize(hFile, &cbToCopy);
-        if (RT_FAILURE(rc))
-            break;
-
-        /* Copy the content from hFile over to pszTargetName. */
-        uint64_t cbAllWritten = 0; /* Already copied */
-        uint64_t cbRead = 0; /* Actually read in the last step */
-        for (;;)
-        {
-            if (pfnProgressCallback)
-                pfnProgressCallback((unsigned)(100.0 / cbOverallSize * cbOverallWritten), pvUser);
-
-            /* Finished already? */
-            if (cbAllWritten == cbToCopy)
-                break;
-
-            /* Read one block. */
-            cbRead = RT_MIN(cbToCopy - cbAllWritten, cbTmp);
-            rc = RTTarFileRead(hFile, pvTmp, cbRead, NULL);
-            if (RT_FAILURE(rc))
-                break;
-
-            /* Write the block */
-            rc = RTFileWrite(hNewFile, pvTmp, cbRead, NULL);
-            if (RT_FAILURE(rc))
-                break;
-
-            /* Count how many bytes are written already */
-            cbAllWritten += cbRead;
-            cbOverallWritten += cbRead;
-        }
-
-    } while(0);
-
-    /* Cleanup */
-    if (pvTmp)
-        RTMemTmpFree(pvTmp);
-
-    /* Now set all file attributes */
-    if (RT_SUCCESS(rc))
-    {
-        uint32_t mode;
-        rc = RTTarFileGetMode(hFile, &mode);
-        if (RT_SUCCESS(rc))
-        {
-            mode |= RTFS_TYPE_FILE; /* For now we support regular files only */
-            /* Set the mode */
-            rc = RTFileSetMode(hNewFile, mode);
-        }
-    }
-
-    RTFileClose(hNewFile);
-
-    /* Delete the freshly created file in the case of an error */
-    if (RT_FAILURE(rc))
-        RTFileDelete(pszTargetName);
-
-    return rc;
-}
-
-static int rtTarAppendFileFromFile(RTTAR hTar, const char *pszSrcName, const uint64_t cbOverallSize, uint64_t &cbOverallWritten, PFNRTPROGRESS pfnProgressCallback, void *pvUser)
-{
-    /* Open the source file */
-    RTFILE hOldFile;
-    int rc = RTFileOpen(&hOldFile, pszSrcName, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
-    if (RT_FAILURE(rc))
-        return rc;
-
-    RTTARFILE hFile = NIL_RTTARFILE;
-    void *pvTmp = NULL;
-    do
-    {
-        /* Get the size of the source file */
-        uint64_t cbToCopy;
-        rc = RTFileGetSize(hOldFile, &cbToCopy);
-        if (RT_FAILURE(rc))
-            break;
-
-        rc = RTTarFileOpen(hTar, &hFile, RTPathFilename(pszSrcName), RTFILE_O_OPEN | RTFILE_O_WRITE);
-        if (RT_FAILURE(rc))
-            break;
-
-        /* Get some info from the source file */
-        RTFSOBJINFO info;
-        RTUID uid = 0;
-        RTGID gid = 0;
-        RTFMODE fmode = 0600; /* Make some save default */
-        int64_t mtime = 0;
-
-        /* This isn't critical. Use the defaults if it fails. */
-        rc = RTFileQueryInfo(hOldFile, &info, RTFSOBJATTRADD_UNIX);
-        if (RT_SUCCESS(rc))
-        {
-            fmode = info.Attr.fMode & RTFS_UNIX_MASK;
-            uid = info.Attr.u.Unix.uid;
-            gid = info.Attr.u.Unix.gid;
-            mtime = RTTimeSpecGetSeconds(&info.ModificationTime);
-        }
-
-        /* Set the mode from the other file */
-        rc = RTTarFileSetMode(hFile, fmode);
-        if (RT_FAILURE(rc))
-            break;
-
-        /* Set the modification time from the other file */
-        RTTIMESPEC time;
-        RTTimeSpecSetSeconds(&time, mtime);
-        rc = RTTarFileSetTime(hFile, &time);
-        if (RT_FAILURE(rc))
-            break;
-
-        /* Set the owner from the other file */
-        rc = RTTarFileSetOwner(hFile, uid, gid);
-        if (RT_FAILURE(rc))
-            break;
-
-        /* Allocate a temporary buffer for copying the tar content in blocks. */
-        size_t cbTmp = 0;
-        pvTmp = rtTarMemTmpAlloc(&cbTmp);
-        if (!pvTmp)
-        {
-            rc = VERR_NO_MEMORY;
-            break;
-        }
-
-        /* Copy the content from pszSrcName over to hFile. This is done block
-         * wise in 512 byte steps. After this copying is finished hFile will be
-         * on a 512 byte boundary, regardless if the file copied is 512 byte
-         * size aligned. */
-        uint64_t cbAllWritten = 0; /* Already copied */
-        uint64_t cbRead       = 0; /* Actually read in the last step */
-        uint64_t cbWrite      = 0; /* Actually write in the last step */
-        for (;;)
-        {
-            if (pfnProgressCallback)
-                pfnProgressCallback((unsigned)(100.0 / cbOverallSize * cbOverallWritten), pvUser);
-            if (cbAllWritten >= cbToCopy)
-                break;
-
-            /* Read one block. Either its the buffer size or the rest of the
-             * file. */
-            cbRead = RT_MIN(cbToCopy - cbAllWritten, cbTmp);
-            rc = RTFileRead(hOldFile, pvTmp, cbRead, NULL);
-            if (RT_FAILURE(rc))
-                break;
-
-            /* Write one block. */
-            rc = RTTarFileWriteAt(hFile, cbAllWritten, pvTmp, cbRead, NULL);
-            if (RT_FAILURE(rc))
-                break;
-
-            /* Count how many bytes (of the original file) are written already */
-            cbAllWritten += cbRead;
-            cbOverallWritten += cbRead;
-        }
-    } while (0);
-
-    /* Cleanup */
-    if (pvTmp)
-        RTMemTmpFree(pvTmp);
-
-    if (hFile)
-        RTTarFileClose(hFile);
-
-    RTFileClose(hOldFile);
-
-    return rc;
-}
-
-static int rtTarSkipData(RTFILE hFile, PRTTARRECORD pRecord)
-{
-    int rc = VINF_SUCCESS;
-    /* Seek over the data parts (512 bytes aligned) */
-    int64_t offSeek = RT_ALIGN(RTStrToInt64(pRecord->h.size), sizeof(RTTARRECORD));
-    if (offSeek > 0)
-        rc = RTFileSeek(hFile, offSeek, RTFILE_SEEK_CURRENT, NULL);
-    return rc;
-}
-
-static int rtTarFindFile(RTFILE hFile, const char *pszFile, uint64_t *poff, uint64_t *pcbSize)
-{
-    /* Assume we are on the file head. */
-    int         rc      = VINF_SUCCESS;
-    bool        fFound  = false;
-    RTTARRECORD record;
-    for (;;)
-    {
-        /* Read & verify a header record */
-        rc = rtTarReadHeaderRecord(hFile, &record);
-        /* Check for error or EOF. */
-        if (RT_FAILURE(rc))
-            break;
-
-        /* We support normal files only */
-        if (   record.h.linkflag == LF_OLDNORMAL
-            || record.h.linkflag == LF_NORMAL)
-        {
-            if (!RTStrCmp(record.h.name, pszFile))
-            {
-                /* Get the file size */
-                rc = RTStrToUInt64Full(record.h.size, 8, pcbSize);
-                if (RT_FAILURE(rc))
-                    break;
-
-                /* Seek back, to position the file pointer at the start of the header. */
-                rc = RTFileSeek(hFile, -(int64_t)sizeof(RTTARRECORD), RTFILE_SEEK_CURRENT, poff);
-                fFound = true;
-                break;
-            }
-        }
-        rc = rtTarSkipData(hFile, &record);
-        if (RT_FAILURE(rc))
-            break;
-    }
-
-    if (rc == VERR_TAR_END_OF_FILE)
-        rc = VINF_SUCCESS;
-
-    /* Something found? */
-    if (    RT_SUCCESS(rc)
-        &&  !fFound)
-        rc = VERR_FILE_NOT_FOUND;
-
-    return rc;
-}
-
-static int rtTarGetFilesOverallSize(RTFILE hFile, const char * const *papszFiles, size_t cFiles, uint64_t *pcbOverallSize)
-{
-    int rc = VINF_SUCCESS;
-    size_t cFound = 0;
-    RTTARRECORD record;
-    for (;;)
-    {
-        /* Read & verify a header record */
-        rc = rtTarReadHeaderRecord(hFile, &record);
-        /* Check for error or EOF. */
-        if (RT_FAILURE(rc))
-            break;
-
-        /* We support normal files only */
-        if (   record.h.linkflag == LF_OLDNORMAL
-            || record.h.linkflag == LF_NORMAL)
-        {
-            for (size_t i = 0; i < cFiles; ++i)
-            {
-                if (!RTStrCmp(record.h.name, papszFiles[i]))
-                {
-                    /* Get the file size */
-                    uint64_t cbSize = 0;
-                    rc = RTStrToUInt64Full(record.h.size, 8, &cbSize);
-
-                    /* Sum up the overall size */
-                    *pcbOverallSize += cbSize;
-                    ++cFound;
-                    break;
-                }
-            }
-            if (   cFound == cFiles
-                || RT_FAILURE(rc))
-                break;
-        }
-        rc = rtTarSkipData(hFile, &record);
-        if (RT_FAILURE(rc))
-            break;
-    }
-    if (rc == VERR_TAR_END_OF_FILE)
-        rc = VINF_SUCCESS;
-
-    /* Make sure the file pointer is at the begin of the file again. */
-    if (RT_SUCCESS(rc))
-        rc = RTFileSeek(hFile, 0, RTFILE_SEEK_BEGIN, 0);
-    return rc;
-}
-
-/******************************************************************************
- *   Public Functions                                                         *
- ******************************************************************************/
-
-RTR3DECL(int) RTTarOpen(PRTTAR phTar, const char *pszTarname, uint32_t fMode, bool fStream)
-{
-    /*
-     * Create a tar instance.
-     */
-    PRTTARINTERNAL pThis = (PRTTARINTERNAL)RTMemAllocZ(sizeof(RTTARINTERNAL));
-    if (!pThis)
-        return VERR_NO_MEMORY;
-
-    pThis->u32Magic    = RTTAR_MAGIC;
-    pThis->fOpenMode   = fMode;
-    pThis->fStreamMode = fStream && (fMode & RTFILE_O_READ);
-
-    /*
-     * Open the tar file.
-     */
-    int rc = RTFileOpen(&pThis->hTarFile, pszTarname, fMode);
-    if (RT_SUCCESS(rc))
-    {
-        *phTar = pThis;
-        return VINF_SUCCESS;
-    }
-
-    RTMemFree(pThis);
-    return rc;
-}
-
-RTR3DECL(int) RTTarClose(RTTAR hTar)
-{
-    if (hTar == NIL_RTTAR)
-        return VINF_SUCCESS;
-
-    PRTTARINTERNAL pInt = hTar;
-    RTTAR_VALID_RETURN(pInt);
-
-    int rc = VINF_SUCCESS;
-
-    /* gtar gives a warning, but the documentation says EOF is indicated by a
-     * zero block. Disabled for now. */
-#if 0
-    {
-        /* Append the EOF record which is filled all by zeros */
-        RTTARRECORD record;
-        RT_ZERO(record);
-        rc = RTFileWrite(pInt->hTarFile, &record, sizeof(record), NULL);
-    }
-#endif
-
-    if (pInt->hTarFile != NIL_RTFILE)
-        rc = RTFileClose(pInt->hTarFile);
-
-    /* Delete any remaining cached file headers. */
-    if (pInt->pFileCache)
-    {
-        rtDeleteTarFileInternal(pInt->pFileCache);
-        pInt->pFileCache = NULL;
-    }
-
-    pInt->u32Magic = RTTAR_MAGIC_DEAD;
-
-    RTMemFree(pInt);
-
-    return rc;
-}
-
-RTR3DECL(int) RTTarFileOpen(RTTAR hTar, PRTTARFILE phFile, const char *pszFilename, uint32_t fOpen)
-{
-    AssertReturn((fOpen & RTFILE_O_READ) || (fOpen & RTFILE_O_WRITE), VERR_INVALID_PARAMETER);
-
-    PRTTARINTERNAL pInt = hTar;
-    RTTAR_VALID_RETURN(pInt);
-
-    if (!pInt->hTarFile)
-        return VERR_INVALID_HANDLE;
-
-    if (pInt->fStreamMode)
-        return VERR_INVALID_STATE;
-
-    if (fOpen & RTFILE_O_WRITE)
-    {
-        if (!(pInt->fOpenMode & RTFILE_O_WRITE))
-            return VERR_WRITE_PROTECT;
-        if (pInt->fFileOpenForWrite)
-            return VERR_TOO_MANY_OPEN_FILES;
-    }
-
-    PRTTARFILEINTERNAL pFileInt = rtCreateTarFileInternal(pInt, pszFilename, fOpen);
-    if (!pFileInt)
-        return VERR_NO_MEMORY;
-
-    int rc = VINF_SUCCESS;
-    do /* break loop */
-    {
-        if (pFileInt->fOpenMode & RTFILE_O_WRITE)
-        {
-            pInt->fFileOpenForWrite = true;
-
-            /* If we are in write mode, we also in append mode. Add an dummy
-             * header at the end of the current file. It will be filled by the
-             * close operation. */
-            rc = RTFileSeek(pFileInt->pTar->hTarFile, 0, RTFILE_SEEK_END, &pFileInt->offStart);
-            if (RT_FAILURE(rc))
-                break;
-            RTTARRECORD record;
-            RT_ZERO(record);
-            rc = RTFileWrite(pFileInt->pTar->hTarFile, &record, sizeof(RTTARRECORD), NULL);
-            if (RT_FAILURE(rc))
-                break;
-        }
-        else if (pFileInt->fOpenMode & RTFILE_O_READ)
-        {
-            /* We need to be on the start of the file */
-            rc = RTFileSeek(pFileInt->pTar->hTarFile, 0, RTFILE_SEEK_BEGIN, NULL);
-            if (RT_FAILURE(rc))
-                break;
-
-            /* Search for the file. */
-            rc = rtTarFindFile(pFileInt->pTar->hTarFile, pszFilename, &pFileInt->offStart, &pFileInt->cbSize);
-            if (RT_FAILURE(rc))
-                break;
-        }
-        else
-        {
-            /** @todo is something missing here? */
-        }
-
-    } while (0);
-
-    /* Cleanup on failure */
-    if (RT_FAILURE(rc))
-    {
-        if (pFileInt->pszFilename)
-            RTStrFree(pFileInt->pszFilename);
-        RTMemFree(pFileInt);
-    }
-    else
-        *phFile = (RTTARFILE)pFileInt;
-
-    return rc;
-}
-
-RTR3DECL(int) RTTarFileClose(RTTARFILE hFile)
-{
-    /* Already closed? */
-    if (hFile == NIL_RTTARFILE)
-        return VINF_SUCCESS;
-
-    PRTTARFILEINTERNAL pFileInt = hFile;
-    RTTARFILE_VALID_RETURN(pFileInt);
-
-    int rc = VINF_SUCCESS;
-
-    /* In write mode: */
-    if (pFileInt->fOpenMode & RTFILE_O_READ)
-    {
-        /* In read mode, we want to make sure to stay at the aligned end of this
-         * file, so the next file could be read immediately. */
-        uint64_t offCur = RTFileTell(pFileInt->pTar->hTarFile);
-
-        /* Check that the file pointer is somewhere within the last open file.
-         * If we are at the beginning (nothing read yet) nothing will be done.
-         * A user could open/close a file more than once, without reading
-         * something. */
-        if (   pFileInt->offStart + sizeof(RTTARRECORD) < offCur
-            && offCur < RT_ALIGN(pFileInt->offStart + sizeof(RTTARRECORD) + pFileInt->cbSize, sizeof(RTTARRECORD)))
-        {
-            /* Seek to the next file header. */
-            uint64_t offNext = RT_ALIGN(pFileInt->offStart + sizeof(RTTARRECORD) + pFileInt->cbSize, sizeof(RTTARRECORD));
-            rc = RTFileSeek(pFileInt->pTar->hTarFile, offNext - offCur, RTFILE_SEEK_CURRENT, NULL);
-        }
-    }
-    else if (pFileInt->fOpenMode & RTFILE_O_WRITE)
-    {
-        pFileInt->pTar->fFileOpenForWrite = false;
-        do
-        {
-            /* If the user has called RTTarFileSetSize in the meantime, we have
-               to make sure the file has the right size. */
-            if (pFileInt->cbSetSize > pFileInt->cbSize)
-            {
-                rc = rtTarAppendZeros(hFile, pFileInt->cbSetSize - pFileInt->cbSize);
-                if (RT_FAILURE(rc))
-                    break;
-            }
-
-            /* If the written size isn't 512 byte aligned, we need to fix this. */
-            RTTARRECORD record;
-            RT_ZERO(record);
-            uint64_t cbSizeAligned = RT_ALIGN(pFileInt->cbSize, sizeof(RTTARRECORD));
-            if (cbSizeAligned != pFileInt->cbSize)
-            {
-                /* Note the RTFile method. We didn't increase the cbSize or cbCurrentPos here. */
-                rc = RTFileWriteAt(pFileInt->pTar->hTarFile,
-                                   pFileInt->offStart + sizeof(RTTARRECORD) + pFileInt->cbSize,
-                                   &record,
-                                   cbSizeAligned - pFileInt->cbSize,
-                                   NULL);
-                if (RT_FAILURE(rc))
-                    break;
-            }
-
-            /* Create a header record for the file */
-            /* Todo: mode, gid, uid, mtime should be setable (or detected myself) */
-            RTTIMESPEC time;
-            RTTimeNow(&time);
-            rc = rtTarCreateHeaderRecord(&record, pFileInt->pszFilename, pFileInt->cbSize,
-                                         0, 0, 0600, RTTimeSpecGetSeconds(&time));
-            if (RT_FAILURE(rc))
-                break;
-
-            /* Write this at the start of the file data */
-            rc = RTFileWriteAt(pFileInt->pTar->hTarFile, pFileInt->offStart, &record, sizeof(RTTARRECORD), NULL);
-            if (RT_FAILURE(rc))
-                break;
-        }
-        while(0);
-    }
-
-    /* Now cleanup and delete the handle */
-    rtDeleteTarFileInternal(pFileInt);
-
-    return rc;
-}
-
-RTR3DECL(int) RTTarFileSeek(RTTARFILE hFile, uint64_t offSeek, unsigned uMethod, uint64_t *poffActual)
-{
-    PRTTARFILEINTERNAL pFileInt = hFile;
-    RTTARFILE_VALID_RETURN(pFileInt);
-
-    if (pFileInt->pTar->fStreamMode)
-        return VERR_INVALID_STATE;
-
-    switch (uMethod)
-    {
-        case RTFILE_SEEK_BEGIN:
-        {
-            if (offSeek > pFileInt->cbSize)
-                return VERR_SEEK_ON_DEVICE;
-            pFileInt->offCurrent = offSeek;
-            break;
-        }
-        case RTFILE_SEEK_CURRENT:
-        {
-            if (pFileInt->offCurrent + offSeek > pFileInt->cbSize)
-                return VERR_SEEK_ON_DEVICE;
-            pFileInt->offCurrent += offSeek;
-            break;
-        }
-        case RTFILE_SEEK_END:
-        {
-            if ((int64_t)pFileInt->cbSize - (int64_t)offSeek < 0)
-                return VERR_NEGATIVE_SEEK;
-            pFileInt->offCurrent = pFileInt->cbSize - offSeek;
-            break;
-        }
-        default: AssertFailedReturn(VERR_INVALID_PARAMETER); break;
-    }
-
-    return VINF_SUCCESS;
-}
-
-RTR3DECL(uint64_t) RTTarFileTell(RTTARFILE hFile)
-{
-    PRTTARFILEINTERNAL pFileInt = hFile;
-    RTTARFILE_VALID_RETURN_RC(pFileInt, UINT64_MAX);
-
-    return pFileInt->offCurrent;
-}
-
-RTR3DECL(int) RTTarFileRead(RTTARFILE hFile, void *pvBuf, size_t cbToRead, size_t *pcbRead)
-{
-    PRTTARFILEINTERNAL pFileInt = hFile;
-    RTTARFILE_VALID_RETURN(pFileInt);
-
-    /* Todo: optimize this, by checking the current pos */
-    return RTTarFileReadAt(hFile, pFileInt->offCurrent, pvBuf, cbToRead, pcbRead);
-}
-
-RTR3DECL(int) RTTarFileReadAt(RTTARFILE hFile, uint64_t off, void *pvBuf, size_t cbToRead, size_t *pcbRead)
-{
-    PRTTARFILEINTERNAL pFileInt = hFile;
-    RTTARFILE_VALID_RETURN(pFileInt);
-
-    /* Check that we not read behind the end of file. If so return immediately. */
-    if (off > pFileInt->cbSize)
-    {
-        if (pcbRead)
-            *pcbRead = 0;
-        return VINF_SUCCESS; /* ??? VERR_EOF */
-    }
-
-    size_t cbToCopy = RT_MIN(pFileInt->cbSize - off, cbToRead);
-    size_t cbTmpRead = 0;
-    int rc = RTFileReadAt(pFileInt->pTar->hTarFile, pFileInt->offStart + 512 + off, pvBuf, cbToCopy, &cbTmpRead);
-    pFileInt->offCurrent = off + cbTmpRead;
-    if (pcbRead)
-        *pcbRead = cbTmpRead;
-
-    return rc;
-}
-
-RTR3DECL(int) RTTarFileWrite(RTTARFILE hFile, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten)
-{
-    PRTTARFILEINTERNAL pFileInt = hFile;
-    RTTARFILE_VALID_RETURN(pFileInt);
-
-    /** @todo Optimize this, by checking the current pos */
-    return RTTarFileWriteAt(hFile, pFileInt->offCurrent, pvBuf, cbToWrite, pcbWritten);
-}
-
-RTR3DECL(int) RTTarFileWriteAt(RTTARFILE hFile, uint64_t off, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten)
-{
-    PRTTARFILEINTERNAL pFileInt = hFile;
-    RTTARFILE_VALID_RETURN(pFileInt);
-
-    if ((pFileInt->fOpenMode & RTFILE_O_WRITE) != RTFILE_O_WRITE)
-        return VERR_WRITE_ERROR;
-
-    size_t cbTmpWritten = 0;
-    int rc = RTFileWriteAt(pFileInt->pTar->hTarFile, pFileInt->offStart + 512 + off, pvBuf, cbToWrite, &cbTmpWritten);
-    pFileInt->cbSize += cbTmpWritten;
-    pFileInt->offCurrent = off + cbTmpWritten;
-    if (pcbWritten)
-        *pcbWritten = cbTmpWritten;
-
-    return rc;
-}
-
-RTR3DECL(int) RTTarFileGetSize(RTTARFILE hFile, uint64_t *pcbSize)
-{
-    /* Validate input */
-    AssertPtrReturn(pcbSize, VERR_INVALID_POINTER);
-
-    PRTTARFILEINTERNAL pFileInt = hFile;
-    RTTARFILE_VALID_RETURN(pFileInt);
-
-    *pcbSize = RT_MAX(pFileInt->cbSetSize, pFileInt->cbSize);
-
-    return VINF_SUCCESS;
-}
-
-RTR3DECL(int) RTTarFileSetSize(RTTARFILE hFile, uint64_t cbSize)
-{
-    PRTTARFILEINTERNAL pFileInt = hFile;
-    RTTARFILE_VALID_RETURN(pFileInt);
-
-    if ((pFileInt->fOpenMode & RTFILE_O_WRITE) != RTFILE_O_WRITE)
-        return VERR_WRITE_ERROR;
-
-    /** @todo If cbSize is smaller than pFileInt->cbSize we have to
-     * truncate the current file. */
-    pFileInt->cbSetSize = cbSize;
-
-    return VINF_SUCCESS;
-}
-
-RTR3DECL(int) RTTarFileGetMode(RTTARFILE hFile, uint32_t *pfMode)
-{
-    /* Validate input */
-    AssertPtrReturn(pfMode, VERR_INVALID_POINTER);
-
-    PRTTARFILEINTERNAL pFileInt = hFile;
-    RTTARFILE_VALID_RETURN(pFileInt);
-
-    /* Read the mode out of the header entry */
-    char szMode[RT_SIZEOFMEMB(RTTARRECORD, h.mode)+1];
-    int rc = RTFileReadAt(pFileInt->pTar->hTarFile,
-                          pFileInt->offStart + RT_OFFSETOF(RTTARRECORD, h.mode),
-                          szMode,
-                          RT_SIZEOFMEMB(RTTARRECORD, h.mode),
-                          NULL);
-    if (RT_FAILURE(rc))
-        return rc;
-    szMode[sizeof(szMode) - 1] = '\0';
-
-    /* Convert it to an integer */
-    return RTStrToUInt32Full(szMode, 8, pfMode);
-}
-
-RTR3DECL(int) RTTarFileSetMode(RTTARFILE hFile, uint32_t fMode)
-{
-    PRTTARFILEINTERNAL pFileInt = hFile;
-    RTTARFILE_VALID_RETURN(pFileInt);
-
-    if ((pFileInt->fOpenMode & RTFILE_O_WRITE) != RTFILE_O_WRITE)
-        return VERR_WRITE_ERROR;
-
-    /* Convert the mode to an string. */
-    char szMode[RT_SIZEOFMEMB(RTTARRECORD, h.mode)];
-    RTStrPrintf(szMode, sizeof(szMode), "%0.7o", fMode);
-
-    /* Write it directly into the header */
-    return RTFileWriteAt(pFileInt->pTar->hTarFile,
-                         pFileInt->offStart + RT_OFFSETOF(RTTARRECORD, h.mode),
-                         szMode,
-                         RT_SIZEOFMEMB(RTTARRECORD, h.mode),
-                         NULL);
-}
-
-RTR3DECL(int) RTTarFileGetTime(RTTARFILE hFile, PRTTIMESPEC pTime)
-{
-    PRTTARFILEINTERNAL pFileInt = hFile;
-    RTTARFILE_VALID_RETURN(pFileInt);
-
-    /* Read the time out of the header entry */
-    char szModTime[RT_SIZEOFMEMB(RTTARRECORD, h.mtime) + 1];
-    int rc = RTFileReadAt(pFileInt->pTar->hTarFile,
-                          pFileInt->offStart + RT_OFFSETOF(RTTARRECORD, h.mtime),
-                          szModTime,
-                          RT_SIZEOFMEMB(RTTARRECORD, h.mtime),
-                          NULL);
-    if (RT_FAILURE(rc))
-        return rc;
-    szModTime[sizeof(szModTime) - 1] = '\0';
-
-    /* Convert it to an integer */
-    int64_t cSeconds;
-    rc = RTStrToInt64Full(szModTime, 12, &cSeconds);
-
-    /* And back to our time structure */
-    if (RT_SUCCESS(rc))
-        RTTimeSpecSetSeconds(pTime, cSeconds);
-
-    return rc;
-}
-
-RTR3DECL(int) RTTarFileSetTime(RTTARFILE hFile, PRTTIMESPEC pTime)
-{
-    PRTTARFILEINTERNAL pFileInt = hFile;
-    RTTARFILE_VALID_RETURN(pFileInt);
-
-    if ((pFileInt->fOpenMode & RTFILE_O_WRITE) != RTFILE_O_WRITE)
-        return VERR_WRITE_ERROR;
-
-    /* Convert the time to an string. */
-    char szModTime[RT_SIZEOFMEMB(RTTARRECORD, h.mtime)];
-    RTStrPrintf(szModTime, sizeof(szModTime), "%0.11o", RTTimeSpecGetSeconds(pTime));
-
-    /* Write it directly into the header */
-    return RTFileWriteAt(pFileInt->pTar->hTarFile,
-                         pFileInt->offStart + RT_OFFSETOF(RTTARRECORD, h.mtime),
-                         szModTime,
-                         RT_SIZEOFMEMB(RTTARRECORD, h.mtime),
-                         NULL);
-}
-
-RTR3DECL(int) RTTarFileGetOwner(RTTARFILE hFile, uint32_t *pUid, uint32_t *pGid)
-{
-    PRTTARFILEINTERNAL pFileInt = hFile;
-    RTTARFILE_VALID_RETURN(pFileInt);
-
-    /* Read the uid and gid out of the header entry */
-    AssertCompileAdjacentMembers(RTTARRECORD, h.uid, h.gid);
-    char szUidGid[RT_SIZEOFMEMB(RTTARRECORD, h.uid) + RT_SIZEOFMEMB(RTTARRECORD, h.gid) + 1];
-    int rc = RTFileReadAt(pFileInt->pTar->hTarFile,
-                          pFileInt->offStart + RT_OFFSETOF(RTTARRECORD, h.uid),
-                          szUidGid,
-                          sizeof(szUidGid) - 1,
-                          NULL);
-    if (RT_FAILURE(rc))
-        return rc;
-    szUidGid[sizeof(szUidGid) - 1] = '\0';
-
-    /* Convert it to integer */
-    rc = RTStrToUInt32Full(&szUidGid[RT_SIZEOFMEMB(RTTARRECORD, h.uid)], 8, pGid);
-    if (RT_SUCCESS(rc))
-    {
-        szUidGid[RT_SIZEOFMEMB(RTTARRECORD, h.uid)] = '\0';
-        rc = RTStrToUInt32Full(szUidGid, 8, pUid);
-    }
-    return rc;
-}
-
-RTR3DECL(int) RTTarFileSetOwner(RTTARFILE hFile, uint32_t uid, uint32_t gid)
-{
-    PRTTARFILEINTERNAL pFileInt = hFile;
-    RTTARFILE_VALID_RETURN(pFileInt);
-
-    if ((pFileInt->fOpenMode & RTFILE_O_WRITE) != RTFILE_O_WRITE)
-        return VERR_WRITE_ERROR;
-    AssertReturn(uid == (uint32_t)-1 || uid <= 07777777, VERR_OUT_OF_RANGE);
-    AssertReturn(gid == (uint32_t)-1 || gid <= 07777777, VERR_OUT_OF_RANGE);
-
-    int rc = VINF_SUCCESS;
-
-    if (uid != (uint32_t)-1)
-    {
-        /* Convert the uid to an string. */
-        char szUid[RT_SIZEOFMEMB(RTTARRECORD, h.uid)];
-        RTStrPrintf(szUid, sizeof(szUid), "%0.7o", uid);
-
-        /* Write it directly into the header */
-        rc = RTFileWriteAt(pFileInt->pTar->hTarFile,
-                           pFileInt->offStart + RT_OFFSETOF(RTTARRECORD, h.uid),
-                           szUid,
-                           RT_SIZEOFMEMB(RTTARRECORD, h.uid),
-                           NULL);
-        if (RT_FAILURE(rc))
-            return rc;
-    }
-
-    if (gid != (uint32_t)-1)
-    {
-        /* Convert the gid to an string. */
-        char szGid[RT_SIZEOFMEMB(RTTARRECORD, h.gid)];
-        RTStrPrintf(szGid, sizeof(szGid), "%0.7o", gid);
-
-        /* Write it directly into the header */
-        rc = RTFileWriteAt(pFileInt->pTar->hTarFile,
-                           pFileInt->offStart + RT_OFFSETOF(RTTARRECORD, h.gid),
-                           szGid,
-                           RT_SIZEOFMEMB(RTTARRECORD, h.gid),
-                           NULL);
-        if (RT_FAILURE(rc))
-            return rc;
-    }
-
-    return rc;
-}
-
-/******************************************************************************
- *   Convenience Functions                                                    *
- ******************************************************************************/
-
-RTR3DECL(int) RTTarFileExists(const char *pszTarFile, const char *pszFile)
-{
-    /* Validate input */
-    AssertPtrReturn(pszTarFile, VERR_INVALID_POINTER);
-    AssertPtrReturn(pszFile, VERR_INVALID_POINTER);
-
-    /* Open the tar file */
-    RTTAR hTar;
-    int rc = RTTarOpen(&hTar, pszTarFile, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE, false /*fStream*/);
-    if (RT_FAILURE(rc))
-        return rc;
-
-    /* Just try to open that file readonly. If this succeed the file exists. */
-    RTTARFILE hFile;
-    rc = RTTarFileOpen(hTar, &hFile, pszFile, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE);
-    if (RT_SUCCESS(rc))
-        RTTarFileClose(hFile);
-
-    RTTarClose(hTar);
-
-    return rc;
-}
-
-RTR3DECL(int) RTTarList(const char *pszTarFile, char ***ppapszFiles, size_t *pcFiles)
-{
-    /* Validate input */
-    AssertPtrReturn(pszTarFile, VERR_INVALID_POINTER);
-    AssertPtrReturn(ppapszFiles, VERR_INVALID_POINTER);
-    AssertPtrReturn(pcFiles, VERR_INVALID_POINTER);
-
-    /* Open the tar file */
-    RTTAR hTar;
-    int rc = RTTarOpen(&hTar, pszTarFile, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE, false /*fStream*/);
-    if (RT_FAILURE(rc))
-        return rc;
-
-    /* This is done by internal methods, cause we didn't have a RTTARDIR
-     * interface, yet. This should be fixed someday. */
-
-    PRTTARINTERNAL pInt = hTar;
-    char **papszFiles = NULL;
-    size_t cFiles = 0;
-    do /* break loop */
-    {
-        /* Initialize the file name array with one slot */
-        size_t cFilesAlloc = 1;
-        papszFiles = (char **)RTMemAlloc(sizeof(char *));
-        if (!papszFiles)
-        {
-            rc = VERR_NO_MEMORY;
-            break;
-        }
-
-        /* Iterate through the tar file record by record. Skip data records as we
-         * didn't need them. */
-        RTTARRECORD record;
-        for (;;)
-        {
-            /* Read & verify a header record */
-            rc = rtTarReadHeaderRecord(pInt->hTarFile, &record);
-            /* Check for error or EOF. */
-            if (RT_FAILURE(rc))
-                break;
-            /* We support normal files only */
-            if (   record.h.linkflag == LF_OLDNORMAL
-                || record.h.linkflag == LF_NORMAL)
-            {
-                if (cFiles >= cFilesAlloc)
-                {
-                    /* Double the array size, make sure the size doesn't wrap. */
-                    void  *pvNew = NULL;
-                    size_t cbNew = cFilesAlloc * sizeof(char *) * 2;
-                    if (cbNew / sizeof(char *) / 2 == cFilesAlloc)
-                        pvNew = RTMemRealloc(papszFiles, cbNew);
-                    if (!pvNew)
-                    {
-                        rc = VERR_NO_MEMORY;
-                        break;
-                    }
-                    papszFiles = (char **)pvNew;
-                    cFilesAlloc *= 2;
-                }
-
-                /* Duplicate the name */
-                papszFiles[cFiles] = RTStrDup(record.h.name);
-                if (!papszFiles[cFiles])
-                {
-                    rc = VERR_NO_MEMORY;
-                    break;
-                }
-                cFiles++;
-            }
-            rc = rtTarSkipData(pInt->hTarFile, &record);
-            if (RT_FAILURE(rc))
-                break;
-        }
-    } while(0);
-
-    if (rc == VERR_TAR_END_OF_FILE)
-        rc = VINF_SUCCESS;
-
-    /* Return the file array on success, dispose of it on failure. */
-    if (RT_SUCCESS(rc))
-    {
-        *pcFiles = cFiles;
-        *ppapszFiles = papszFiles;
-    }
-    else
-    {
-        while (cFiles-- > 0)
-            RTStrFree(papszFiles[cFiles]);
-        RTMemFree(papszFiles);
-    }
-
-    RTTarClose(hTar);
-
-    return rc;
-}
-
-RTR3DECL(int) RTTarExtractFileToBuf(const char *pszTarFile, void **ppvBuf, size_t *pcbSize, const char *pszFile,
-                                    PFNRTPROGRESS pfnProgressCallback, void *pvUser)
-{
-    /*
-     * Validate input
-     */
-    AssertPtrReturn(pszTarFile, VERR_INVALID_POINTER);
-    AssertPtrReturn(ppvBuf, VERR_INVALID_POINTER);
-    AssertPtrReturn(pcbSize, VERR_INVALID_POINTER);
-    AssertPtrReturn(pszFile, VERR_INVALID_POINTER);
-    AssertPtrNullReturn(pfnProgressCallback, VERR_INVALID_POINTER);
-    AssertPtrNullReturn(pvUser, VERR_INVALID_POINTER);
-
-    /** @todo progress bar - is this TODO still valid? */
-
-    int         rc      = VINF_SUCCESS;
-    RTTAR       hTar    = NIL_RTTAR;
-    RTTARFILE   hFile   = NIL_RTTARFILE;
-    char       *pvTmp   = NULL;
-    uint64_t    cbToCopy= 0;
-    do /* break loop */
-    {
-        rc = RTTarOpen(&hTar, pszTarFile, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE, false /*fStream*/);
-        if (RT_FAILURE(rc))
-            break;
-        rc = RTTarFileOpen(hTar, &hFile, pszFile, RTFILE_O_OPEN | RTFILE_O_READ);
-        if (RT_FAILURE(rc))
-            break;
-        rc = RTTarFileGetSize(hFile, &cbToCopy);
-        if (RT_FAILURE(rc))
-            break;
-
-        /* Allocate the memory for the file content. */
-        pvTmp = (char *)RTMemAlloc(cbToCopy);
-        if (!pvTmp)
-        {
-            rc = VERR_NO_MEMORY;
-            break;
-        }
-        size_t cbRead = 0;
-        size_t cbAllRead = 0;
-        for (;;)
-        {
-            if (pfnProgressCallback)
-                pfnProgressCallback((unsigned)(100.0 / cbToCopy * cbAllRead), pvUser);
-            if (cbAllRead == cbToCopy)
-                break;
-            rc = RTTarFileReadAt(hFile, 0, &pvTmp[cbAllRead], cbToCopy - cbAllRead, &cbRead);
-            if (RT_FAILURE(rc))
-                break;
-            cbAllRead += cbRead;
-        }
-    } while (0);
-
-    /* Set output values on success */
-    if (RT_SUCCESS(rc))
-    {
-        *pcbSize = cbToCopy;
-        *ppvBuf = pvTmp;
-    }
-
-    /* Cleanup */
-    if (   RT_FAILURE(rc)
-        && pvTmp)
-        RTMemFree(pvTmp);
-    if (hFile)
-        RTTarFileClose(hFile);
-    if (hTar)
-        RTTarClose(hTar);
-
-    return rc;
-}
-
-RTR3DECL(int) RTTarExtractFiles(const char *pszTarFile, const char *pszOutputDir, const char * const *papszFiles,
-                                size_t cFiles, PFNRTPROGRESS pfnProgressCallback, void *pvUser)
-{
-    /* Validate input */
-    AssertPtrReturn(pszTarFile, VERR_INVALID_POINTER);
-    AssertPtrReturn(pszOutputDir, VERR_INVALID_POINTER);
-    AssertPtrReturn(papszFiles, VERR_INVALID_POINTER);
-    AssertReturn(cFiles, VERR_INVALID_PARAMETER);
-    AssertPtrNullReturn(pfnProgressCallback, VERR_INVALID_POINTER);
-    AssertPtrNullReturn(pvUser, VERR_INVALID_POINTER);
-
-    /* Open the tar file */
-    RTTAR hTar;
-    int rc = RTTarOpen(&hTar, pszTarFile, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE, false /*fStream*/);
-    if (RT_FAILURE(rc))
-        return rc;
-
-    do /* break loop */
-    {
-        /* Get the overall size of all files to extract out of the tar archive
-           headers. Only necessary if there is a progress callback. */
-        uint64_t cbOverallSize = 0;
-        if (pfnProgressCallback)
-        {
-//            rc = rtTarGetFilesOverallSize(hFile, papszFiles, cFiles, &cbOverallSize);
-//            if (RT_FAILURE(rc))
-//                break;
-        }
-
-        uint64_t cbOverallWritten = 0;
-        for (size_t i = 0; i < cFiles; ++i)
-        {
-            RTTARFILE hFile;
-            rc = RTTarFileOpen(hTar, &hFile, papszFiles[i], RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE);
-            if (RT_FAILURE(rc))
-                break;
-            char *pszTargetFile = RTPathJoinA(pszOutputDir, papszFiles[i]);
-            if (pszTargetFile)
-                rc = rtTarExtractFileToFile(hFile, pszTargetFile, cbOverallSize, cbOverallWritten, pfnProgressCallback, pvUser);
-            else
-                rc = VERR_NO_STR_MEMORY;
-            RTStrFree(pszTargetFile);
-            RTTarFileClose(hFile);
-            if (RT_FAILURE(rc))
-                break;
-        }
-    } while (0);
-
-    RTTarClose(hTar);
-
-    return rc;
-}
-
-RTR3DECL(int) RTTarExtractAll(const char *pszTarFile, const char *pszOutputDir, PFNRTPROGRESS pfnProgressCallback, void *pvUser)
-{
-    /* Validate input */
-    AssertPtrReturn(pszTarFile, VERR_INVALID_POINTER);
-    AssertPtrReturn(pszOutputDir, VERR_INVALID_POINTER);
-    AssertPtrNullReturn(pfnProgressCallback, VERR_INVALID_POINTER);
-    AssertPtrNullReturn(pvUser, VERR_INVALID_POINTER);
-
-    char **papszFiles;
-    size_t cFiles;
-
-    /* First fetch the files names contained in the tar file */
-    int rc = RTTarList(pszTarFile, &papszFiles, &cFiles);
-    if (RT_FAILURE(rc))
-        return rc;
-
-    /* Extract all files */
-    return RTTarExtractFiles(pszTarFile, pszOutputDir, papszFiles, cFiles, pfnProgressCallback, pvUser);
-}
-
-RTR3DECL(int) RTTarCreate(const char *pszTarFile, const char * const *papszFiles, size_t cFiles, PFNRTPROGRESS pfnProgressCallback, void *pvUser)
-{
-    /* Validate input */
-    AssertPtrReturn(pszTarFile, VERR_INVALID_POINTER);
-    AssertPtrReturn(papszFiles, VERR_INVALID_POINTER);
-    AssertReturn(cFiles, VERR_INVALID_PARAMETER);
-    AssertPtrNullReturn(pfnProgressCallback, VERR_INVALID_POINTER);
-    AssertPtrNullReturn(pvUser, VERR_INVALID_POINTER);
-
-    RTTAR hTar;
-    int rc = RTTarOpen(&hTar, pszTarFile, RTFILE_O_CREATE | RTFILE_O_READWRITE | RTFILE_O_DENY_NONE, false /*fStream*/);
-    if (RT_FAILURE(rc))
-        return rc;
-
-    /* Get the overall size of all files to pack into the tar archive. Only
-       necessary if there is a progress callback. */
-    uint64_t cbOverallSize = 0;
-    if (pfnProgressCallback)
-        for (size_t i = 0; i < cFiles; ++i)
-        {
-            uint64_t cbSize;
-            rc = RTFileQuerySize(papszFiles[i], &cbSize);
-            if (RT_FAILURE(rc))
-                break;
-            cbOverallSize += cbSize;
-        }
-    uint64_t cbOverallWritten = 0;
-    for (size_t i = 0; i < cFiles; ++i)
-    {
-        rc = rtTarAppendFileFromFile(hTar, papszFiles[i], cbOverallSize, cbOverallWritten, pfnProgressCallback, pvUser);
-        if (RT_FAILURE(rc))
-            break;
-    }
-
-    /* Cleanup */
-    RTTarClose(hTar);
-
-    return rc;
-}
-
-/******************************************************************************
- *   Streaming Functions                                                      *
- ******************************************************************************/
-
-RTR3DECL(int) RTTarCurrentFile(RTTAR hTar, char **ppszFilename)
-{
-    /* Validate input. */
-    AssertPtrNullReturn(ppszFilename, VERR_INVALID_POINTER);
-
-    PRTTARINTERNAL pInt = hTar;
-    RTTAR_VALID_RETURN(pInt);
-
-    /* Open and close the file on the current position. This makes sure the
-     * cache is filled in case we never read something before. On success it
-     * will return the current filename. */
-    RTTARFILE hFile;
-    int rc = RTTarFileOpenCurrentFile(hTar, &hFile, ppszFilename, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE);
-    if (RT_SUCCESS(rc))
-        RTTarFileClose(hFile);
-
-    return rc;
-}
-
-RTR3DECL(int) RTTarSeekNextFile(RTTAR hTar)
-{
-    PRTTARINTERNAL pInt = hTar;
-    RTTAR_VALID_RETURN(pInt);
-
-    int rc = VINF_SUCCESS;
-
-    if (!pInt->fStreamMode)
-        return VERR_INVALID_STATE;
-
-    /* If there is nothing in the cache, it means we never read something. Just
-     * ask for the current filename to fill the cache. */
-    if (!pInt->pFileCache)
-    {
-        rc = RTTarCurrentFile(hTar, NULL);
-        if (RT_FAILURE(rc))
-            return rc;
-    }
-
-    /* Check that the file pointer is somewhere within the last open file.
-     * If not we are somehow busted. */
-    uint64_t offCur = RTFileTell(pInt->hTarFile);
-    if (!(   pInt->pFileCache->offStart <= offCur
-          && offCur < pInt->pFileCache->offStart + sizeof(RTTARRECORD) + pInt->pFileCache->cbSize))
-        return VERR_INVALID_STATE;
-
-    /* Seek to the next file header. */
-    uint64_t offNext = RT_ALIGN(pInt->pFileCache->offStart + sizeof(RTTARRECORD) + pInt->pFileCache->cbSize, sizeof(RTTARRECORD));
-    rc = RTFileSeek(pInt->hTarFile, offNext - offCur, RTFILE_SEEK_CURRENT, NULL);
-    if (RT_FAILURE(rc))
-        return rc;
-
-    /* Again check the current filename to fill the cache with the new value. */
-    return RTTarCurrentFile(hTar, NULL);
-}
-
-RTR3DECL(int) RTTarFileOpenCurrentFile(RTTAR hTar, PRTTARFILE phFile, char **ppszFilename, uint32_t fOpen)
-{
-    /* Validate input. */
-    AssertPtrReturn(phFile, VERR_INVALID_POINTER);
-    AssertPtrNullReturn(ppszFilename, VERR_INVALID_POINTER);
-    AssertReturn((fOpen & RTFILE_O_READ), VERR_INVALID_PARAMETER); /* Only valid in read mode. */
-
-    PRTTARINTERNAL pInt = hTar;
-    RTTAR_VALID_RETURN(pInt);
-
-    if (!pInt->fStreamMode)
-        return VERR_INVALID_STATE;
-
-    int rc = VINF_SUCCESS;
-
-    /* Is there some cached entry? */
-    if (pInt->pFileCache)
-    {
-        /* Are we still direct behind that header? */
-        if (pInt->pFileCache->offStart + sizeof(RTTARRECORD) == RTFileTell(pInt->hTarFile))
-        {
-            /* Yes, so the streaming can start. Just return the cached file
-             * structure to the caller. */
-            *phFile = rtCopyTarFileInternal(pInt->pFileCache);
-            if (ppszFilename)
-                *ppszFilename = RTStrDup(pInt->pFileCache->pszFilename);
-            return VINF_SUCCESS;
-        }
-
-        /* Else delete the last open file cache. Might be recreated below. */
-        rtDeleteTarFileInternal(pInt->pFileCache);
-        pInt->pFileCache = NULL;
-    }
-
-    PRTTARFILEINTERNAL pFileInt = NULL;
-    do /* break loop */
-    {
-        /* Try to read a header entry from the current position. If we aren't
-         * on a header record, the header checksum will show and an error will
-         * be returned. */
-        RTTARRECORD record;
-        /* Read & verify a header record */
-        rc = rtTarReadHeaderRecord(pInt->hTarFile, &record);
-        /* Check for error or EOF. */
-        if (RT_FAILURE(rc))
-            break;
-
-        /* We support normal files only */
-        if (   record.h.linkflag == LF_OLDNORMAL
-            || record.h.linkflag == LF_NORMAL)
-        {
-            pFileInt = rtCreateTarFileInternal(pInt, record.h.name, fOpen);
-            if (!pFileInt)
-            {
-                rc = VERR_NO_MEMORY;
-                break;
-            }
-
-            /* Get the file size */
-            rc = RTStrToUInt64Full(record.h.size, 8, &pFileInt->cbSize);
-            if (RT_FAILURE(rc))
-                break;
-
-            /* The start is -512 from here. */
-            pFileInt->offStart = RTFileTell(pInt->hTarFile) - sizeof(RTTARRECORD);
-
-            /* Copy the new file structure to our cache. */
-            pInt->pFileCache = rtCopyTarFileInternal(pFileInt);
-            if (ppszFilename)
-                *ppszFilename = RTStrDup(pFileInt->pszFilename);
-        }
-    } while (0);
-
-    if (RT_FAILURE(rc))
-    {
-        if (pFileInt)
-            rtDeleteTarFileInternal(pFileInt);
-    }
-    else
-        *phFile = pFileInt;
-
-    return rc;
-}
-
Index: trunk/src/VBox/Runtime/common/misc/zip.cpp
===================================================================
--- trunk/src/VBox/Runtime/common/misc/zip.cpp	(revision 33804)
+++ 	(revision )
@@ -1,1908 +1,0 @@
-/* $Id$ */
-/** @file
- * IPRT - Compression.
- */
-
-/*
- * Copyright (C) 2006-2009 Oracle Corporation
- *
- * This file is part of VirtualBox Open Source Edition (OSE), as
- * available from http://www.virtualbox.org. This file is free software;
- * you can redistribute it and/or modify it under the terms of the GNU
- * General Public License (GPL) as published by the Free Software
- * Foundation, in version 2 as it comes in the "COPYING" file of the
- * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
- * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
- *
- * The contents of this file may alternatively be used under the terms
- * of the Common Development and Distribution License Version 1.0
- * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
- * VirtualBox OSE distribution, in which case the provisions of the
- * CDDL are applicable instead of those of the GPL.
- *
- * You may elect to license modified versions of this file under the
- * terms and conditions of either the GPL or the CDDL or both.
- */
-
-
-/*******************************************************************************
-*   Defined Constants And Macros                                               *
-*******************************************************************************/
-#define RTZIP_USE_STORE 1
-#define RTZIP_USE_ZLIB 1
-//#define RTZIP_USE_BZLIB 1
-#define RTZIP_USE_LZF 1
-#define RTZIP_LZF_BLOCK_BY_BLOCK
-//#define RTZIP_USE_LZJB 1
-//#define RTZIP_USE_LZO 1
-
-/** @todo FastLZ? QuickLZ? Others? */
-
-
-/*******************************************************************************
-*   Header Files                                                               *
-*******************************************************************************/
-#ifdef RTZIP_USE_BZLIB
-# include <bzlib.h>
-#endif
-#ifdef RTZIP_USE_ZLIB
-# include <zlib.h>
-#endif
-#ifdef RTZIP_USE_LZF
-# include <lzf.h>
-# include <iprt/crc.h>
-#endif
-#ifdef RTZIP_USE_LZJB
-# include "lzjb.h"
-#endif
-#ifdef RTZIP_USE_LZO
-# include <lzo/lzo1x.h>
-#endif
-
-#include <iprt/zip.h>
-#include "internal/iprt.h"
-
-/*#include <iprt/asm.h>*/
-#include <iprt/alloc.h>
-#include <iprt/assert.h>
-#include <iprt/err.h>
-#include <iprt/log.h>
-#include <iprt/string.h>
-
-#include <errno.h>
-
-
-/*******************************************************************************
-*   Structures and Typedefs                                                    *
-*******************************************************************************/
-
-#ifdef RTZIP_USE_LZF
-
-/**
- * LZF block header.
- */
-#pragma pack(1)                         /* paranoia */
-typedef struct RTZIPLZFHDR
-{
-    /** Magic word (RTZIPLZFHDR_MAGIC). */
-    uint16_t    u16Magic;
-    /** The number of bytes of data following this header. */
-    uint16_t    cbData;
-    /** The CRC32 of the block. */
-    uint32_t    u32CRC;
-    /** The size of the uncompressed data in bytes. */
-    uint16_t    cbUncompressed;
-} RTZIPLZFHDR;
-#pragma pack()
-/** Pointer to a LZF block header. */
-typedef RTZIPLZFHDR *PRTZIPLZFHDR;
-/** Pointer to a const LZF block header. */
-typedef const RTZIPLZFHDR *PCRTZIPLZFHDR;
-
-/** The magic of a LZF block header. */
-#define RTZIPLZFHDR_MAGIC                       ('Z' | ('V' << 8))
-
-/** The max compressed data size.
- * The maximum size of a block is currently 16KB.
- * This is very important so we don't have to move input buffers around. */
-#define RTZIPLZF_MAX_DATA_SIZE                  (16384 - sizeof(RTZIPLZFHDR))
-
-/** The max uncompressed data size.
- * This is important so we don't overflow the spill buffer in the decompressor. */
-#define RTZIPLZF_MAX_UNCOMPRESSED_DATA_SIZE     (32*_1K)
-
-#endif /* RTZIP_USE_LZF */
-
-
-/**
- * Compressor/Decompressor instance data.
- */
-typedef struct RTZIPCOMP
-{
-    /** Output buffer. */
-    uint8_t             abBuffer[_128K];
-    /** Compression output consumer. */
-    PFNRTZIPOUT         pfnOut;
-    /** User argument for the callback. */
-    void               *pvUser;
-
-    /**
-     * @copydoc RTZipCompress
-     */
-    DECLCALLBACKMEMBER(int, pfnCompress)(PRTZIPCOMP pZip, const void *pvBuf, size_t cbBuf);
-
-    /**
-     * @copydoc RTZipCompFinish
-     */
-    DECLCALLBACKMEMBER(int, pfnFinish)(PRTZIPCOMP pZip);
-
-    /**
-     * @copydoc RTZipCompDestroy
-     */
-    DECLCALLBACKMEMBER(int, pfnDestroy)(PRTZIPCOMP pZip);
-
-    /** Compression type. */
-    RTZIPTYPE           enmType;
-    /** Type specific data. */
-    union
-    {
-#ifdef RTZIP_USE_STORE
-        /** Simple storing. */
-        struct
-        {
-            /** Current buffer position. (where to start write) */
-            uint8_t    *pb;
-        } Store;
-#endif
-#ifdef RTZIP_USE_ZLIB
-        /** Zlib stream. */
-        z_stream        Zlib;
-#endif
-#ifdef RTZIP_USE_BZLIB
-        /** BZlib stream. */
-        bz_stream       BZlib;
-#endif
-#ifdef RTZIP_USE_LZF
-        /** LZF stream. */
-        struct
-        {
-            /** Current output buffer position. */
-            uint8_t    *pbOutput;
-            /** The input buffer position. */
-            uint8_t    *pbInput;
-            /** The number of free bytes in the input buffer. */
-            size_t      cbInputFree;
-            /** The input buffer. */
-            uint8_t     abInput[RTZIPLZF_MAX_UNCOMPRESSED_DATA_SIZE];
-        } LZF;
-#endif
-
-    } u;
-} RTZIPCOMP;
-
-
-
-/**
- * Decompressor instance data.
- */
-typedef struct RTZIPDECOMP
-{
-    /** Input buffer. */
-    uint8_t             abBuffer[_128K];
-    /** Decompression input producer. */
-    PFNRTZIPIN          pfnIn;
-    /** User argument for the callback. */
-    void               *pvUser;
-
-    /**
-     * @copydoc RTZipDecompress
-     */
-    DECLCALLBACKMEMBER(int, pfnDecompress)(PRTZIPDECOMP pZip, void *pvBuf, size_t cbBuf, size_t *pcbWritten);
-
-    /**
-     * @copydoc RTZipDecompDestroy
-     */
-    DECLCALLBACKMEMBER(int, pfnDestroy)(PRTZIPDECOMP pZip);
-
-    /** Compression type. */
-    RTZIPTYPE           enmType;
-    /** Type specific data. */
-    union
-    {
-#ifdef RTZIP_USE_STORE
-        /** Simple storing. */
-        struct
-        {
-            /** Current buffer position. (where to start read) */
-            uint8_t    *pb;
-            /** Number of bytes left in the buffer. */
-            size_t      cbBuffer;
-        } Store;
-#endif
-#ifdef RTZIP_USE_ZLIB
-        /** Zlib stream. */
-        z_stream        Zlib;
-#endif
-#ifdef RTZIP_USE_BZLIB
-        /** BZlib stream. */
-        bz_stream       BZlib;
-#endif
-#ifdef RTZIP_USE_LZF
-        /** LZF 'stream'. */
-        struct
-        {
-# ifndef RTZIP_LZF_BLOCK_BY_BLOCK
-            /** Current input buffer position. */
-            uint8_t    *pbInput;
-            /** The number of bytes left in the input buffer. */
-            size_t      cbInput;
-# endif
-            /** The spill buffer.
-             * LZF is a block based compressor and not a stream compressor. So,
-             * we have to decompress full blocks if we want to get any of the data.
-             * This buffer is to store the spill after decompressing a block. */
-            uint8_t     abSpill[RTZIPLZF_MAX_UNCOMPRESSED_DATA_SIZE];
-            /** The number of bytes left spill buffer. */
-            unsigned    cbSpill;
-            /** The current spill buffer position. */
-            uint8_t    *pbSpill;
-        } LZF;
-#endif
-
-    } u;
-} RTZIPDECOM;
-
-
-
-#ifdef RTZIP_USE_STORE
-
-/**
- * @copydoc RTZipCompress
- */
-static DECLCALLBACK(int) rtZipStoreCompress(PRTZIPCOMP pZip, const void *pvBuf, size_t cbBuf)
-{
-    uint8_t *pbDst = pZip->u.Store.pb;
-    while (cbBuf)
-    {
-        /*
-         * Flush.
-         */
-        size_t cb = sizeof(pZip->abBuffer) - (size_t)(pbDst - &pZip->abBuffer[0]); /* careful here, g++ 4.1.2 screws up easily */
-        if (cb == 0)
-        {
-            int rc = pZip->pfnOut(pZip->pvUser, &pZip->abBuffer[0], sizeof(pZip->abBuffer));
-            if (RT_FAILURE(rc))
-                return rc;
-
-            cb = sizeof(pZip->abBuffer);
-            pbDst = &pZip->abBuffer[0];
-        }
-
-        /*
-         * Add to the buffer and advance.
-         */
-        if (cbBuf < cb)
-            cb = cbBuf;
-        memcpy(pbDst, pvBuf, cb);
-
-        pbDst += cb;
-        cbBuf -= cb;
-        pvBuf = (uint8_t *)pvBuf + cb;
-    }
-    pZip->u.Store.pb = pbDst;
-    return VINF_SUCCESS;
-}
-
-
-/**
- * @copydoc RTZipCompFinish
- */
-static DECLCALLBACK(int) rtZipStoreCompFinish(PRTZIPCOMP pZip)
-{
-    size_t cb = (uintptr_t)pZip->u.Store.pb - (uintptr_t)&pZip->abBuffer[0];
-    if (cb > 0)
-    {
-        int rc = pZip->pfnOut(pZip->pvUser, &pZip->abBuffer[0], cb);
-        if (RT_FAILURE(rc))
-            return rc;
-    }
-    return VINF_SUCCESS;
-}
-
-
-/**
- * @copydoc RTZipCompDestroy
- */
-static DECLCALLBACK(int) rtZipStoreCompDestroy(PRTZIPCOMP pZip)
-{
-    return VINF_SUCCESS;
-}
-
-
-/**
- * Initializes the compressor instance.
- * @returns iprt status code.
- * @param   pZip        The compressor instance.
- * @param   enmLevel    The desired compression level.
- */
-static DECLCALLBACK(int) rtZipStoreCompInit(PRTZIPCOMP pZip, RTZIPLEVEL enmLevel)
-{
-    pZip->pfnCompress = rtZipStoreCompress;
-    pZip->pfnFinish   = rtZipStoreCompFinish;
-    pZip->pfnDestroy  = rtZipStoreCompDestroy;
-
-    pZip->u.Store.pb = &pZip->abBuffer[1];
-    return VINF_SUCCESS;
-}
-
-
-/**
- * @copydoc RTZipDecompress
- */
-static DECLCALLBACK(int) rtZipStoreDecompress(PRTZIPDECOMP pZip, void *pvBuf, size_t cbBuf, size_t *pcbWritten)
-{
-    size_t cbWritten = 0;
-    while (cbBuf)
-    {
-        /*
-         * Fill buffer.
-         */
-        size_t cb = pZip->u.Store.cbBuffer;
-        if (cb <= 0)
-        {
-            int rc = pZip->pfnIn(pZip->pvUser, &pZip->abBuffer[0], sizeof(pZip->abBuffer), &cb);
-            if (RT_FAILURE(rc))
-                return rc;
-            pZip->u.Store.cbBuffer = cb;
-            pZip->u.Store.pb = &pZip->abBuffer[0];
-        }
-
-        /*
-         * No more data?
-         */
-        if (cb == 0)
-        {
-            if (pcbWritten)
-            {
-                *pcbWritten = cbWritten;
-                return VINF_SUCCESS;
-            }
-            return VERR_NO_DATA;
-        }
-
-        /*
-         * Add to the buffer and advance.
-         */
-        if (cbBuf < cb)
-            cb = cbBuf;
-        memcpy(pvBuf, pZip->u.Store.pb, cb);
-        pZip->u.Store.pb += cb;
-        pZip->u.Store.cbBuffer -= cb;
-        cbBuf -= cb;
-        pvBuf = (char *)pvBuf + cb;
-        cbWritten += cb;
-    }
-    if (pcbWritten)
-        *pcbWritten = cbWritten;
-    return VINF_SUCCESS;
-}
-
-
-/**
- * @copydoc RTZipDecompDestroy
- */
-static DECLCALLBACK(int) rtZipStoreDecompDestroy(PRTZIPDECOMP pZip)
-{
-    return VINF_SUCCESS;
-}
-
-
-/**
- * Initialize the decompressor instance.
- * @returns iprt status code.
- * @param   pZip        The decompressor instance.
- */
-static DECLCALLBACK(int) rtZipStoreDecompInit(PRTZIPDECOMP pZip)
-{
-    pZip->pfnDecompress = rtZipStoreDecompress;
-    pZip->pfnDestroy = rtZipStoreDecompDestroy;
-
-    pZip->u.Store.pb = &pZip->abBuffer[0];
-    pZip->u.Store.cbBuffer = 0;
-    return VINF_SUCCESS;
-}
-
-#endif /* RTZIP_USE_STORE */
-
-
-#ifdef RTZIP_USE_ZLIB
-/**
- * Convert from zlib errno to iprt status code.
- * @returns iprt status code.
- * @param   rc      Zlib error code.
- */
-static int zipErrConvertFromZlib(int rc)
-{
-    /** @todo proper zlib error conversion. */
-    switch (rc)
-    {
-        case Z_ERRNO:
-            return RTErrConvertFromErrno(errno);
-        case Z_STREAM_ERROR:
-        case Z_DATA_ERROR:
-        case Z_MEM_ERROR:
-        case Z_BUF_ERROR:
-        case Z_VERSION_ERROR:
-            return VERR_GENERAL_FAILURE;
-        default:
-            if (rc >= 0)
-                return VINF_SUCCESS;
-            return VERR_GENERAL_FAILURE;
-    }
-}
-
-
-/**
- * @copydoc RTZipCompress
- */
-static DECLCALLBACK(int) rtZipZlibCompress(PRTZIPCOMP pZip, const void *pvBuf, size_t cbBuf)
-{
-    pZip->u.Zlib.next_in  = (Bytef *)pvBuf;
-    pZip->u.Zlib.avail_in = (uInt)cbBuf;                    Assert(pZip->u.Zlib.avail_in == cbBuf);
-    while (pZip->u.Zlib.avail_in > 0)
-    {
-        /*
-         * Flush output buffer?
-         */
-        if (pZip->u.Zlib.avail_out <= 0)
-        {
-            int rc = pZip->pfnOut(pZip->pvUser, &pZip->abBuffer[0], sizeof(pZip->abBuffer) - pZip->u.Zlib.avail_out);
-            if (RT_FAILURE(rc))
-                return rc;
-            pZip->u.Zlib.avail_out = sizeof(pZip->abBuffer);
-            pZip->u.Zlib.next_out = &pZip->abBuffer[0];
-        }
-
-        /*
-         * Pass it on to zlib.
-         */
-        int rc = deflate(&pZip->u.Zlib, Z_NO_FLUSH);
-        if (rc != Z_OK)
-            return zipErrConvertFromZlib(rc);
-    }
-    return VINF_SUCCESS;
-}
-
-
-/**
- * @copydoc RTZipCompFinish
- */
-static DECLCALLBACK(int) rtZipZlibCompFinish(PRTZIPCOMP pZip)
-{
-    int rc = Z_OK;
-    for (;;)
-    {
-        /*
-         * Flush outstanding stuff. writes.
-         */
-        if (rc == Z_STREAM_END || pZip->u.Zlib.avail_out <= 0)
-        {
-            int rc2 = pZip->pfnOut(pZip->pvUser, &pZip->abBuffer[0], sizeof(pZip->abBuffer) - pZip->u.Zlib.avail_out);
-            if (RT_FAILURE(rc2))
-                return rc2;
-            pZip->u.Zlib.avail_out = sizeof(pZip->abBuffer);
-            pZip->u.Zlib.next_out = &pZip->abBuffer[0];
-            if (rc == Z_STREAM_END)
-                return VINF_SUCCESS;
-        }
-
-        /*
-         * Tell zlib to flush.
-         */
-        rc = deflate(&pZip->u.Zlib, Z_FINISH);
-        if (rc != Z_OK && rc != Z_STREAM_END)
-            return zipErrConvertFromZlib(rc);
-    }
-    return VINF_SUCCESS;
-}
-
-
-/**
- * @copydoc RTZipCompDestroy
- */
-static DECLCALLBACK(int) rtZipZlibCompDestroy(PRTZIPCOMP pZip)
-{
-    /*
-     * Terminate the deflate instance.
-     */
-    int rc = deflateEnd(&pZip->u.Zlib);
-    if (rc != Z_OK)
-        rc = zipErrConvertFromZlib(rc);
-    return rc;
-}
-
-
-/**
- * Initializes the compressor instance.
- * @returns iprt status code.
- * @param   pZip        The compressor instance.
- * @param   enmLevel    The desired compression level.
- */
-static DECLCALLBACK(int) rtZipZlibCompInit(PRTZIPCOMP pZip, RTZIPLEVEL enmLevel)
-{
-    pZip->pfnCompress = rtZipZlibCompress;
-    pZip->pfnFinish   = rtZipZlibCompFinish;
-    pZip->pfnDestroy  = rtZipZlibCompDestroy;
-
-    int iLevel = Z_DEFAULT_COMPRESSION;
-    switch (enmLevel)
-    {
-        case RTZIPLEVEL_STORE:      iLevel = 0; break;
-        case RTZIPLEVEL_FAST:       iLevel = 2; break;
-        case RTZIPLEVEL_DEFAULT:    iLevel = Z_DEFAULT_COMPRESSION; break;
-        case RTZIPLEVEL_MAX:        iLevel = 9; break;
-    }
-
-    memset(&pZip->u.Zlib, 0, sizeof(pZip->u.Zlib));
-    pZip->u.Zlib.next_out  = &pZip->abBuffer[1];
-    pZip->u.Zlib.avail_out = sizeof(pZip->abBuffer) - 1;
-    pZip->u.Zlib.opaque    = pZip;
-
-    int rc = deflateInit(&pZip->u.Zlib, enmLevel);
-    return rc >= 0 ? rc = VINF_SUCCESS : zipErrConvertFromZlib(rc);
-}
-
-
-/**
- * @copydoc RTZipDecompress
- */
-static DECLCALLBACK(int) rtZipZlibDecompress(PRTZIPDECOMP pZip, void *pvBuf, size_t cbBuf, size_t *pcbWritten)
-{
-    pZip->u.Zlib.next_out = (Bytef *)pvBuf;
-    pZip->u.Zlib.avail_out = (uInt)cbBuf;                   Assert(pZip->u.Zlib.avail_out == cbBuf);
-
-    /*
-     * Be greedy reading input, even if no output buffer is left. It's possible
-     * that it's just the end of stream marker which needs to be read. Happens
-     * for incompressible blocks just larger than the input buffer size.
-     */
-    while (pZip->u.Zlib.avail_out > 0 || pZip->u.Zlib.avail_in <= 0)
-    {
-        /*
-         * Read more input?
-         */
-        if (pZip->u.Zlib.avail_in <= 0)
-        {
-            size_t cb = sizeof(pZip->abBuffer);
-            int rc = pZip->pfnIn(pZip->pvUser, &pZip->abBuffer[0], sizeof(pZip->abBuffer), &cb);
-            if (RT_FAILURE(rc))
-                return rc;
-            pZip->u.Zlib.avail_in = (uInt)cb;               Assert(pZip->u.Zlib.avail_in == cb);
-            pZip->u.Zlib.next_in = &pZip->abBuffer[0];
-        }
-
-        /*
-         * Pass it on to zlib.
-         */
-        int rc = inflate(&pZip->u.Zlib, Z_NO_FLUSH);
-        if (rc == Z_STREAM_END)
-        {
-            if (pcbWritten)
-                *pcbWritten = cbBuf - pZip->u.Zlib.avail_out;
-            else if (pZip->u.Zlib.avail_out > 0)
-                return VERR_NO_DATA;
-            break;
-        }
-        if (rc != Z_OK)
-            return zipErrConvertFromZlib(rc);
-    }
-    return VINF_SUCCESS;
-}
-
-
-/**
- * @copydoc RTZipDecompDestroy
- */
-static DECLCALLBACK(int) rtZipZlibDecompDestroy(PRTZIPDECOMP pZip)
-{
-    /*
-     * Terminate the deflate instance.
-     */
-    int rc = inflateEnd(&pZip->u.Zlib);
-    if (rc != Z_OK)
-        rc = zipErrConvertFromZlib(rc);
-    return rc;
-}
-
-
-/**
- * Initialize the decompressor instance.
- * @returns iprt status code.
- * @param   pZip        The decompressor instance.
- */
-static DECLCALLBACK(int) rtZipZlibDecompInit(PRTZIPDECOMP pZip)
-{
-    pZip->pfnDecompress = rtZipZlibDecompress;
-    pZip->pfnDestroy = rtZipZlibDecompDestroy;
-
-    memset(&pZip->u.Zlib, 0, sizeof(pZip->u.Zlib));
-    pZip->u.Zlib.opaque    = pZip;
-
-    int rc = inflateInit(&pZip->u.Zlib);
-    return rc >= 0 ? VINF_SUCCESS : zipErrConvertFromZlib(rc);
-}
-
-#endif /* RTZIP_USE_ZLIB */
-
-
-#ifdef RTZIP_USE_BZLIB
-/**
- * Convert from BZlib errno to iprt status code.
- * @returns iprt status code.
- * @param   rc      BZlib error code.
- */
-static int zipErrConvertFromBZlib(int rc)
-{
-    /** @todo proper bzlib error conversion. */
-    switch (rc)
-    {
-        case BZ_SEQUENCE_ERROR:
-            AssertMsgFailed(("BZ_SEQUENCE_ERROR shall not happen!\n"));
-            return VERR_GENERAL_FAILURE;
-        case BZ_PARAM_ERROR:
-            return VERR_INVALID_PARAMETER;
-        case BZ_MEM_ERROR:
-            return VERR_NO_MEMORY;
-        case BZ_DATA_ERROR:
-        case BZ_DATA_ERROR_MAGIC:
-        case BZ_IO_ERROR:
-        case BZ_UNEXPECTED_EOF:
-        case BZ_CONFIG_ERROR:
-            return VERR_GENERAL_FAILURE;
-        case BZ_OUTBUFF_FULL:
-            AssertMsgFailed(("BZ_OUTBUFF_FULL shall not happen!\n"));
-            return VERR_GENERAL_FAILURE;
-        default:
-            if (rc >= 0)
-                return VINF_SUCCESS;
-            return VERR_GENERAL_FAILURE;
-    }
-}
-
-
-/**
- * @copydoc RTZipCompress
- */
-static DECLCALLBACK(int) rtZipBZlibCompress(PRTZIPCOMP pZip, const void *pvBuf, size_t cbBuf)
-{
-    pZip->u.BZlib.next_in  = (char *)pvBuf;
-    pZip->u.BZlib.avail_in = cbBuf;
-    while (pZip->u.BZlib.avail_in > 0)
-    {
-        /*
-         * Flush output buffer?
-         */
-        if (pZip->u.BZlib.avail_out <= 0)
-        {
-            int rc = pZip->pfnOut(pZip->pvUser, &pZip->abBuffer[0], sizeof(pZip->abBuffer) - pZip->u.BZlib.avail_out);
-            if (RT_FAILURE(rc))
-                return rc;
-            pZip->u.BZlib.avail_out = sizeof(pZip->abBuffer);
-            pZip->u.BZlib.next_out = (char *)&pZip->abBuffer[0];
-        }
-
-        /*
-         * Pass it on to zlib.
-         */
-        int rc = BZ2_bzCompress(&pZip->u.BZlib, BZ_RUN);
-        if (rc < 0 && rc != BZ_OUTBUFF_FULL)
-            return zipErrConvertFromBZlib(rc);
-    }
-    return VINF_SUCCESS;
-}
-
-
-/**
- * @copydoc RTZipCompFinish
- */
-static DECLCALLBACK(int) rtZipBZlibCompFinish(PRTZIPCOMP pZip)
-{
-    int rc = BZ_FINISH_OK;
-    for (;;)
-    {
-        /*
-         * Flush output buffer?
-         */
-        if (rc == BZ_STREAM_END || pZip->u.BZlib.avail_out <= 0)
-        {
-            int rc2 = pZip->pfnOut(pZip->pvUser, &pZip->abBuffer[0], sizeof(pZip->abBuffer) - pZip->u.BZlib.avail_out);
-            if (RT_FAILURE(rc2))
-                return rc2;
-            pZip->u.BZlib.avail_out = sizeof(pZip->abBuffer);
-            pZip->u.BZlib.next_out = (char *)&pZip->abBuffer[0];
-            if (rc == BZ_STREAM_END)
-                return VINF_SUCCESS;
-        }
-
-        /*
-         * Tell BZlib to finish it.
-         */
-        rc = BZ2_bzCompress(&pZip->u.BZlib, BZ_FINISH);
-        if (rc < 0 && rc != BZ_OUTBUFF_FULL)
-            return zipErrConvertFromBZlib(rc);
-    }
-    return VINF_SUCCESS;
-}
-
-
-/**
- * @copydoc RTZipCompDestroy
- */
-static DECLCALLBACK(int) rtZipBZlibCompDestroy(PRTZIPCOMP pZip)
-{
-    /*
-     * Terminate the deflate instance.
-     */
-    int rc = BZ2_bzCompressEnd(&pZip->u.BZlib);
-    if (rc != BZ_OK)
-        rc = zipErrConvertFromBZlib(rc);
-    return rc;
-}
-
-
-/**
- * Initializes the compressor instance.
- * @returns iprt status code.
- * @param   pZip        The compressor instance.
- * @param   enmLevel    The desired compression level.
- */
-static DECLCALLBACK(int) rtZipBZlibCompInit(PRTZIPCOMP pZip, RTZIPLEVEL enmLevel)
-{
-    pZip->pfnCompress = rtZipBZlibCompress;
-    pZip->pfnFinish   = rtZipBZlibCompFinish;
-    pZip->pfnDestroy  = rtZipBZlibCompDestroy;
-
-    int iSize = 6;
-    int iWork = 0;
-    switch (enmLevel)
-    {
-        case RTZIPLEVEL_STORE:      iSize = 1; iWork = 2; break;
-        case RTZIPLEVEL_FAST:       iSize = 2; iWork = 0; break;
-        case RTZIPLEVEL_DEFAULT:    iSize = 5; iWork = 0; break;
-        case RTZIPLEVEL_MAX:        iSize = 9; iWork = 0; break;
-    }
-
-    memset(&pZip->u.BZlib, 0, sizeof(pZip->u.BZlib));
-    pZip->u.BZlib.next_out  = (char *)&pZip->abBuffer[1];
-    pZip->u.BZlib.avail_out = sizeof(pZip->abBuffer) - 1;
-    pZip->u.BZlib.opaque    = pZip;
-
-    int rc = BZ2_bzCompressInit(&pZip->u.BZlib, iSize, 0, iWork);
-    return rc >= 0 ? VINF_SUCCESS : zipErrConvertFromBZlib(rc);;
-}
-
-
-/**
- * @copydoc RTZipDecompress
- */
-static DECLCALLBACK(int) rtZipBZlibDecompress(PRTZIPDECOMP pZip, void *pvBuf, size_t cbBuf, size_t *pcbWritten)
-{
-    pZip->u.BZlib.next_out  = (char *)pvBuf;
-    pZip->u.BZlib.avail_out = cbBuf;
-    while (pZip->u.BZlib.avail_out > 0)
-    {
-        /*
-         * Read more output buffer?
-         */
-        if (pZip->u.BZlib.avail_in <= 0)
-        {
-            size_t cb;
-            int rc = pZip->pfnIn(pZip->pvUser, &pZip->abBuffer[0], sizeof(pZip->abBuffer), &cb);
-            if (RT_FAILURE(rc))
-                return rc;
-            pZip->u.BZlib.avail_in = cb;
-            pZip->u.BZlib.next_in = (char *)&pZip->abBuffer[0];
-        }
-
-        /*
-         * Pass it on to zlib.
-         */
-        int rc = BZ2_bzDecompress(&pZip->u.BZlib);
-        if (rc == BZ_STREAM_END || rc == BZ_OUTBUFF_FULL)
-        {
-            if (pcbWritten)
-                *pcbWritten = cbBuf - pZip->u.BZlib.avail_out;
-            else if (pZip->u.BZlib.avail_out > 0)
-                return VERR_NO_DATA;
-            break;
-        }
-        if (rc < 0)
-            return zipErrConvertFromBZlib(rc);
-    }
-    return VINF_SUCCESS;
-}
-
-
-/**
- * @copydoc RTZipDecompDestroy
- */
-static DECLCALLBACK(int) rtZipBZlibDecompDestroy(PRTZIPDECOMP pZip)
-{
-    /*
-     * Terminate the deflate instance.
-     */
-    int rc = BZ2_bzDecompressEnd(&pZip->u.BZlib);
-    if (rc != BZ_OK)
-        rc = zipErrConvertFromBZlib(rc);
-    return rc;
-}
-
-
-/**
- * Initialize the decompressor instance.
- * @returns iprt status code.
- * @param   pZip        The decompressor instance.
- */
-static DECLCALLBACK(int) rtZipBZlibDecompInit(PRTZIPDECOMP pZip)
-{
-    pZip->pfnDecompress = rtZipBZlibDecompress;
-    pZip->pfnDestroy = rtZipBZlibDecompDestroy;
-
-    memset(&pZip->u.BZlib, 0, sizeof(pZip->u.BZlib));
-    pZip->u.BZlib.opaque    = pZip;
-
-    int rc = BZ2_bzDecompressInit(&pZip->u.BZlib, 0, 0);
-    return rc >= 0 ? VINF_SUCCESS : zipErrConvertFromBZlib(rc);
-}
-
-#endif /* RTZIP_USE_BZLIB */
-
-
-#ifdef RTZIP_USE_LZF
-
-/**
- * Flushes the output buffer.
- * @returns iprt status code.
- * @param   pZip        The compressor instance.
- */
-static int rtZipLZFCompFlushOutput(PRTZIPCOMP pZip)
-{
-    size_t      cb = pZip->u.LZF.pbOutput - &pZip->abBuffer[0];
-    pZip->u.LZF.pbOutput = &pZip->abBuffer[0];
-    return pZip->pfnOut(pZip->pvUser, &pZip->abBuffer[0], cb);
-}
-
-
-/**
- * Compresses a buffer using LZF.
- *
- * @returns VBox status code.
- * @param   pZip        The compressor instance.
- * @param   pbBuf       What to compress.
- * @param   cbBuf       How much to compress.
- */
-static int rtZipLZFCompressBuffer(PRTZIPCOMP pZip, const uint8_t *pbBuf, size_t cbBuf)
-{
-    bool fForceFlush = false;
-    while (cbBuf > 0)
-    {
-        /*
-         * Flush output buffer?
-         */
-        unsigned cbFree = (unsigned)(sizeof(pZip->abBuffer) - (pZip->u.LZF.pbOutput - &pZip->abBuffer[0]));
-        if (    fForceFlush
-            ||  cbFree < RTZIPLZF_MAX_DATA_SIZE + sizeof(RTZIPLZFHDR))
-        {
-            int rc = rtZipLZFCompFlushOutput(pZip);
-            if (RT_FAILURE(rc))
-                return rc;
-            fForceFlush = false;
-            cbFree = sizeof(pZip->abBuffer);
-        }
-
-        /*
-         * Setup the block header.
-         */
-        PRTZIPLZFHDR pHdr = (PRTZIPLZFHDR)pZip->u.LZF.pbOutput; /* warning: This might be unaligned! */
-        pHdr->u16Magic = RTZIPLZFHDR_MAGIC;
-        pHdr->cbData = 0;
-        pHdr->u32CRC = 0;
-        pHdr->cbUncompressed = 0;
-        cbFree -= sizeof(*pHdr);
-        pZip->u.LZF.pbOutput += sizeof(*pHdr);
-
-        /*
-         * Compress data for the block.
-         *
-         * We try compress as much as we have freespace for at first,
-         * but if it turns out the compression is inefficient, we'll
-         * reduce the size of data we try compress till it fits the
-         * output space.
-         */
-        cbFree = RT_MIN(cbFree, RTZIPLZF_MAX_DATA_SIZE);
-        unsigned cbInput = (unsigned)RT_MIN(RTZIPLZF_MAX_UNCOMPRESSED_DATA_SIZE, cbBuf);
-        unsigned cbOutput = lzf_compress(pbBuf, cbInput, pZip->u.LZF.pbOutput, cbFree);
-        if (!cbOutput)
-        {
-            /** @todo add an alternative method which stores the raw data if bad compression. */
-            do
-            {
-                cbInput /= 2;
-                if (!cbInput)
-                {
-                    AssertMsgFailed(("lzf_compress bug! cbFree=%zu\n", cbFree));
-                    return VERR_INTERNAL_ERROR;
-                }
-                cbOutput = lzf_compress(pbBuf, cbInput, pZip->u.LZF.pbOutput, cbFree);
-            } while (!cbOutput);
-            fForceFlush = true;
-        }
-
-        /*
-         * Update the header and advance the input buffer.
-         */
-        pHdr->cbData = cbOutput;
-        //pHdr->u32CRC = RTCrc32(pbBuf, cbInput); - too slow
-        pHdr->cbUncompressed = cbInput;
-
-        pZip->u.LZF.pbOutput += cbOutput;
-        cbBuf -= cbInput;
-        pbBuf += cbInput;
-    }
-    return VINF_SUCCESS;
-}
-
-
-/**
- * Flushes the input buffer.
- * @returns iprt status code.
- * @param   pZip        The compressor instance.
- */
-static int rtZipLZFCompFlushInput(PRTZIPCOMP pZip)
-{
-    size_t cb = pZip->u.LZF.pbInput - &pZip->u.LZF.abInput[0];
-    pZip->u.LZF.pbInput = &pZip->u.LZF.abInput[0];
-    pZip->u.LZF.cbInputFree = sizeof(pZip->u.LZF.abInput);
-    if (cb)
-        return rtZipLZFCompressBuffer(pZip, pZip->u.LZF.abInput, cb);
-    return VINF_SUCCESS;
-}
-
-
-/**
- * @copydoc RTZipCompress
- */
-static DECLCALLBACK(int) rtZipLZFCompress(PRTZIPCOMP pZip, const void *pvBuf, size_t cbBuf)
-{
-#define RTZIPLZF_SMALL_CHUNK (128)
-
-    /*
-     * Flush the input buffer if necessary.
-     */
-    if (    (   cbBuf <= RTZIPLZF_SMALL_CHUNK
-             && cbBuf > pZip->u.LZF.cbInputFree)
-        ||  (   cbBuf > RTZIPLZF_SMALL_CHUNK
-             && pZip->u.LZF.cbInputFree != sizeof(pZip->u.LZF.abInput))
-       )
-    {
-        int rc = rtZipLZFCompFlushInput(pZip);
-        if (RT_FAILURE(rc))
-            return rc;
-    }
-
-    /*
-     * If it's a relativly small block put it in the input buffer, elsewise
-     * compress directly it.
-     */
-    if (cbBuf <= RTZIPLZF_SMALL_CHUNK)
-    {
-        Assert(pZip->u.LZF.cbInputFree >= cbBuf);
-        memcpy(pZip->u.LZF.pbInput, pvBuf, cbBuf);
-        pZip->u.LZF.pbInput += cbBuf;
-        pZip->u.LZF.cbInputFree -= cbBuf;
-    }
-    else
-    {
-        Assert(pZip->u.LZF.cbInputFree == sizeof(pZip->u.LZF.abInput));
-        int rc = rtZipLZFCompressBuffer(pZip, (const uint8_t *)pvBuf, cbBuf);
-        if (RT_FAILURE(rc))
-            return rc;
-    }
-    return VINF_SUCCESS;
-}
-
-
-/**
- * @copydoc RTZipCompFinish
- */
-static DECLCALLBACK(int) rtZipLZFCompFinish(PRTZIPCOMP pZip)
-{
-    int rc = rtZipLZFCompFlushInput(pZip);
-    if (RT_SUCCESS(rc))
-        rc = rtZipLZFCompFlushOutput(pZip);
-    return rc;
-}
-
-
-/**
- * @copydoc RTZipCompDestroy
- */
-static DECLCALLBACK(int) rtZipLZFCompDestroy(PRTZIPCOMP pZip)
-{
-    return VINF_SUCCESS;
-}
-
-
-/**
- * Initializes the compressor instance.
- * @returns iprt status code.
- * @param   pZip        The compressor instance.
- * @param   enmLevel    The desired compression level.
- */
-static DECLCALLBACK(int) rtZipLZFCompInit(PRTZIPCOMP pZip, RTZIPLEVEL enmLevel)
-{
-    pZip->pfnCompress = rtZipLZFCompress;
-    pZip->pfnFinish   = rtZipLZFCompFinish;
-    pZip->pfnDestroy  = rtZipLZFCompDestroy;
-
-    pZip->u.LZF.pbOutput = &pZip->abBuffer[1];
-    pZip->u.LZF.pbInput  = &pZip->u.LZF.abInput[0];
-    pZip->u.LZF.cbInputFree = sizeof(pZip->u.LZF.abInput);
-    return VINF_SUCCESS;
-}
-
-
-/**
- * This will validate a header and to all the necessary bitching if it's invalid.
- * @returns true if valid.
- * @returns false if invalid.
- * @param   pHdr        Pointer to the header.\
- */
-static bool rtZipLZFValidHeader(PCRTZIPLZFHDR pHdr)
-{
-    if (    pHdr->u16Magic != RTZIPLZFHDR_MAGIC
-        ||  !pHdr->cbData
-        ||  pHdr->cbData > RTZIPLZF_MAX_DATA_SIZE
-        ||  !pHdr->cbUncompressed
-        ||  pHdr->cbUncompressed > RTZIPLZF_MAX_UNCOMPRESSED_DATA_SIZE
-       )
-    {
-        AssertMsgFailed(("Invalid LZF header! %.*%Rhxs\n", sizeof(pHdr), pHdr));
-        return false;
-    }
-    return true;
-}
-
-
-/**
- * @copydoc RTZipDecompress
- */
-static DECLCALLBACK(int) rtZipLZFDecompress(PRTZIPDECOMP pZip, void *pvBuf, size_t cbBuf, size_t *pcbWritten)
-{
-    /*
-     * Decompression loop.
-     *
-     * This a bit ugly because we have to deal with reading block...
-     * To simplify matters we've put a max block size and will never
-     * fill the input buffer with more than allows us to complete
-     * any partially read blocks.
-     *
-     * When possible we decompress directly to the user buffer, when
-     * not possible we'll use the spill buffer.
-     */
-# ifdef RTZIP_LZF_BLOCK_BY_BLOCK
-    size_t cbWritten = 0;
-    while (cbBuf > 0)
-    {
-        /*
-         * Anything in the spill buffer?
-         */
-        if (pZip->u.LZF.cbSpill > 0)
-        {
-            unsigned cb = (unsigned)RT_MIN(pZip->u.LZF.cbSpill, cbBuf);
-            memcpy(pvBuf, pZip->u.LZF.pbSpill, cb);
-            pZip->u.LZF.pbSpill += cb;
-            pZip->u.LZF.cbSpill -= cb;
-            cbWritten += cb;
-            cbBuf -= cb;
-            if (!cbBuf)
-                break;
-            pvBuf = (uint8_t *)pvBuf + cb;
-        }
-
-        /*
-         * We always read and work one block at a time.
-         */
-        RTZIPLZFHDR Hdr;
-        int rc = pZip->pfnIn(pZip->pvUser, &Hdr, sizeof(Hdr), NULL);
-        if (RT_FAILURE(rc))
-            return rc;
-        if (!rtZipLZFValidHeader(&Hdr))
-            return VERR_GENERAL_FAILURE; /** @todo Get better error codes for RTZip! */
-        if (Hdr.cbData > 0)
-        {
-            rc = pZip->pfnIn(pZip->pvUser, &pZip->abBuffer[0], Hdr.cbData, NULL);
-            if (RT_FAILURE(rc))
-                return rc;
-        }
-
-        /*
-         * Does the uncompressed data fit into the supplied buffer?
-         * If so we uncompress it directly into the user buffer, else we'll have to use the spill buffer.
-         */
-        unsigned cbUncompressed = Hdr.cbUncompressed;
-        if (cbUncompressed <= cbBuf)
-        {
-            unsigned cbOutput = lzf_decompress(&pZip->abBuffer[0], Hdr.cbData, pvBuf, cbUncompressed);
-            if (cbOutput != cbUncompressed)
-            {
-                AssertMsgFailed(("Decompression error, errno=%d. cbOutput=%#x cbUncompressed=%#x\n",
-                                 errno, cbOutput, cbUncompressed));
-                return VERR_GENERAL_FAILURE; /** @todo Get better error codes for RTZip! */
-            }
-            cbBuf -= cbUncompressed;
-            pvBuf = (uint8_t *)pvBuf + cbUncompressed;
-            cbWritten += cbUncompressed;
-        }
-        else
-        {
-            unsigned cbOutput = lzf_decompress(&pZip->abBuffer[0], Hdr.cbData, pZip->u.LZF.abSpill, cbUncompressed);
-            if (cbOutput != cbUncompressed)
-            {
-                AssertMsgFailed(("Decompression error, errno=%d. cbOutput=%#x cbUncompressed=%#x\n",
-                                 errno, cbOutput, cbUncompressed));
-                return VERR_GENERAL_FAILURE; /** @todo Get better error codes for RTZip! */
-            }
-            pZip->u.LZF.pbSpill = &pZip->u.LZF.abSpill[0];
-            pZip->u.LZF.cbSpill = cbUncompressed;
-        }
-    }
-
-    if (pcbWritten)
-        *pcbWritten = cbWritten;
-# else  /* !RTZIP_LZF_BLOCK_BY_BLOCK */
-    while (cbBuf > 0)
-    {
-        /*
-         * Anything in the spill buffer?
-         */
-        if (pZip->u.LZF.cbSpill > 0)
-        {
-            unsigned cb = (unsigned)RT_MIN(pZip->u.LZF.cbSpill, cbBuf);
-            memcpy(pvBuf, pZip->u.LZF.pbSpill, cb);
-            pZip->u.LZF.pbSpill += cb;
-            pZip->u.LZF.cbSpill -= cb;
-            cbBuf -= cb;
-            if (pcbWritten)
-                *pcbWritten = cb;
-            if (!cbBuf)
-                break;
-            pvBuf = (uint8_t *)pvBuf + cb;
-        }
-
-        /*
-         * Incomplete header or nothing at all.
-         */
-        PCRTZIPLZFHDR pHdr;
-        if (pZip->u.LZF.cbInput < sizeof(RTZIPLZFHDR))
-        {
-            if (pZip->u.LZF.cbInput <= 0)
-            {
-                /* empty, fill the buffer. */
-                size_t cb = 0;
-                int rc = pZip->pfnIn(pZip->pvUser, &pZip->abBuffer[0],
-                                     sizeof(pZip->abBuffer) - RTZIPLZF_MAX_DATA_SIZE, &cb);
-                if (RT_FAILURE(rc))
-                    return rc;
-                pZip->u.LZF.pbInput = &pZip->abBuffer[0];
-                pZip->u.LZF.cbInput = cb;
-                pHdr = (PCRTZIPLZFHDR)pZip->u.LZF.pbInput;
-            }
-            else
-            {
-                /* move the header up and fill the buffer. */
-                size_t cbCur = pZip->u.LZF.cbInput;
-                memmove(&pZip->abBuffer[0], pZip->u.LZF.pbInput, cbCur);
-                pZip->u.LZF.pbInput = &pZip->abBuffer[0];
-
-                size_t cb = 0;
-                int rc = pZip->pfnIn(pZip->pvUser, &pZip->abBuffer[cbCur],
-                                     sizeof(pZip->abBuffer) - RTZIPLZF_MAX_DATA_SIZE - cbCur, &cb);
-                if (RT_FAILURE(rc))
-                    return rc;
-                pHdr = (PCRTZIPLZFHDR)pZip->u.LZF.pbInput;
-                pZip->u.LZF.cbInput += cb;
-            }
-
-            /*
-             * Validate the header.
-             */
-            if (!rtZipLZFValidHeader(pHdr))
-                return VERR_GENERAL_FAILURE; /** @todo Get better error codes for RTZip! */
-        }
-        else
-        {
-            /*
-             * Validate the header and check if it's an incomplete block.
-             */
-            pHdr = (PCRTZIPLZFHDR)pZip->u.LZF.pbInput;
-            if (!rtZipLZFValidHeader(pHdr))
-                return VERR_GENERAL_FAILURE; /** @todo Get better error codes for RTZip! */
-
-            if (pHdr->cbData > pZip->u.LZF.cbInput - sizeof(*pHdr))
-            {
-                /* read the remainder of the block. */
-                size_t cbToRead = pHdr->cbData - (pZip->u.LZF.cbInput - sizeof(*pHdr));
-                Assert(&pZip->u.LZF.pbInput[pZip->u.LZF.cbInput + cbToRead] <= &pZip->u.LZF.pbInput[sizeof(pZip->abBuffer)]);
-                int rc = pZip->pfnIn(pZip->pvUser, &pZip->u.LZF.pbInput[pZip->u.LZF.cbInput],
-                                     cbToRead, NULL);
-                if (RT_FAILURE(rc))
-                    return rc;
-                pZip->u.LZF.cbInput += cbToRead;
-            }
-        }
-        AssertMsgReturn(sizeof(*pHdr) + pHdr->cbData <= pZip->u.LZF.cbInput,
-                        ("cbData=%#x cbInput=%#x\n", pHdr->cbData, pZip->u.LZF.cbInput),
-                        VERR_GENERAL_FAILURE); /** @todo Get better error codes for RTZip! */
-
-        /*
-         * Does the uncompressed data fit into the supplied buffer?
-         * If so we uncompress it directly into the user buffer, else we'll have to use the spill buffer.
-         */
-        unsigned cbUncompressed = pHdr->cbUncompressed;
-        if (cbUncompressed <= cbBuf)
-        {
-            unsigned cbOutput = lzf_decompress(pHdr + 1, pHdr->cbData, pvBuf, cbUncompressed);
-            if (cbOutput != cbUncompressed)
-            {
-                AssertMsgFailed(("Decompression error, errno=%d. cbOutput=%#x cbUncompressed=%#x\n",
-                                 errno, cbOutput, cbUncompressed));
-                return VERR_GENERAL_FAILURE; /** @todo Get better error codes for RTZip! */
-            }
-            cbBuf -= cbUncompressed;
-            pvBuf = (uint8_t *)pvBuf + cbUncompressed;
-        }
-        else
-        {
-            unsigned cbOutput = lzf_decompress(pHdr + 1, pHdr->cbData, pZip->u.LZF.abSpill, cbUncompressed);
-            if (cbOutput != cbUncompressed)
-            {
-                AssertMsgFailed(("Decompression error, errno=%d. cbOutput=%#x cbUncompressed=%#x\n",
-                                 errno, cbOutput, cbUncompressed));
-                return VERR_GENERAL_FAILURE; /** @todo Get better error codes for RTZip! */
-            }
-            pZip->u.LZF.pbSpill = &pZip->u.LZF.abSpill[0];
-            pZip->u.LZF.cbSpill = cbUncompressed;
-        }
-
-        /* advance the input buffer */
-        pZip->u.LZF.cbInput -= pHdr->cbData + sizeof(*pHdr);
-        pZip->u.LZF.pbInput += pHdr->cbData + sizeof(*pHdr);
-        if (pcbWritten)
-            *pcbWritten += cbUncompressed;
-    }
-# endif /* !RTZIP_LZF_BLOCK_BY_BLOCK */
-    return VINF_SUCCESS;
-}
-
-
-/**
- * @copydoc RTZipDecompDestroy
- */
-static DECLCALLBACK(int) rtZipLZFDecompDestroy(PRTZIPDECOMP pZip)
-{
-    return VINF_SUCCESS;
-}
-
-
-/**
- * Initialize the decompressor instance.
- * @returns iprt status code.
- * @param   pZip        The decompressor instance.
- */
-static DECLCALLBACK(int) rtZipLZFDecompInit(PRTZIPDECOMP pZip)
-{
-    pZip->pfnDecompress = rtZipLZFDecompress;
-    pZip->pfnDestroy = rtZipLZFDecompDestroy;
-
-# ifndef RTZIP_LZF_BLOCK_BY_BLOCK
-    pZip->u.LZF.pbInput    = NULL;
-    pZip->u.LZF.cbInput    = 0;
-# endif
-    pZip->u.LZF.cbSpill    = 0;
-    pZip->u.LZF.pbSpill    = NULL;
-
-    return VINF_SUCCESS;
-}
-
-#endif /* RTZIP_USE_LZF */
-
-
-/**
- * Create a compressor instance.
- *
- * @returns iprt status code.
- * @param   ppZip       Where to store the instance handle.
- * @param   pvUser      User argument which will be passed on to pfnOut and pfnIn.
- * @param   pfnOut      Callback for consuming output of compression.
- * @param   enmType     Type of compressor to create.
- * @param   enmLevel    Compression level.
- */
-RTDECL(int)     RTZipCompCreate(PRTZIPCOMP *ppZip, void *pvUser, PFNRTZIPOUT pfnOut, RTZIPTYPE enmType, RTZIPLEVEL enmLevel)
-{
-    /*
-     * Validate input.
-     */
-    AssertReturn(enmType >= RTZIPTYPE_INVALID && enmType < RTZIPTYPE_END, VERR_INVALID_PARAMETER);
-    AssertReturn(enmLevel >= RTZIPLEVEL_STORE && enmLevel <= RTZIPLEVEL_MAX, VERR_INVALID_PARAMETER);
-    AssertPtrReturn(pfnOut, VERR_INVALID_POINTER);
-    AssertPtrReturn(ppZip, VERR_INVALID_POINTER);
-
-    /*
-     * Allocate memory for the instance data.
-     */
-    PRTZIPCOMP pZip = (PRTZIPCOMP)RTMemAlloc(sizeof(RTZIPCOMP));
-    if (!pZip)
-        return VERR_NO_MEMORY;
-
-    /*
-     * Determine auto type.
-     */
-    if (enmType == RTZIPTYPE_AUTO)
-    {
-        if (enmLevel == RTZIPLEVEL_STORE)
-            enmType = RTZIPTYPE_STORE;
-        else
-        {
-#if defined(RTZIP_USE_ZLIB) && defined(RTZIP_USE_BZLIB)
-            if (enmLevel == RTZIPLEVEL_MAX)
-                enmType = RTZIPTYPE_BZLIB;
-            else
-                enmType = RTZIPTYPE_ZLIB;
-#elif defined(RTZIP_USE_ZLIB)
-            enmType = RTZIPTYPE_ZLIB;
-#elif defined(RTZIP_USE_BZLIB)
-            enmType = RTZIPTYPE_BZLIB;
-#else
-            enmType = RTZIPTYPE_STORE;
-#endif
-        }
-    }
-
-    /*
-     * Init instance.
-     */
-    pZip->pfnOut  = pfnOut;
-    pZip->enmType = enmType;
-    pZip->pvUser  = pvUser;
-    pZip->abBuffer[0] = enmType;       /* first byte is the compression type. */
-    int rc = VERR_NOT_IMPLEMENTED;
-    switch (enmType)
-    {
-        case RTZIPTYPE_STORE:
-#ifdef RTZIP_USE_STORE
-            rc = rtZipStoreCompInit(pZip, enmLevel);
-#endif
-            break;
-
-        case RTZIPTYPE_ZLIB:
-#ifdef RTZIP_USE_ZLIB
-            rc = rtZipZlibCompInit(pZip, enmLevel);
-#endif
-            break;
-
-        case RTZIPTYPE_BZLIB:
-#ifdef RTZIP_USE_BZLIB
-            rc = rtZipBZlibCompInit(pZip, enmLevel);
-#endif
-            break;
-
-        case RTZIPTYPE_LZF:
-#ifdef RTZIP_USE_LZF
-            rc = rtZipLZFCompInit(pZip, enmLevel);
-#endif
-            break;
-
-        case RTZIPTYPE_LZJB:
-        case RTZIPTYPE_LZO:
-            break;
-
-        default:
-            AssertFailedBreak();
-    }
-
-    if (RT_SUCCESS(rc))
-        *ppZip = pZip;
-    else
-        RTMemFree(pZip);
-    return rc;
-}
-RT_EXPORT_SYMBOL(RTZipCompCreate);
-
-
-/**
- * Compresses a chunk of memory.
- *
- * @returns iprt status code.
- * @param   pZip        The compressor instance.
- * @param   pvBuf       Pointer to buffer containing the bits to compress.
- * @param   cbBuf       Number of bytes to compress.
- */
-RTDECL(int)     RTZipCompress(PRTZIPCOMP pZip, const void *pvBuf, size_t cbBuf)
-{
-    if (!cbBuf)
-        return VINF_SUCCESS;
-    return pZip->pfnCompress(pZip, pvBuf, cbBuf);
-}
-RT_EXPORT_SYMBOL(RTZipCompress);
-
-
-/**
- * Finishes the compression.
- * This will flush all data and terminate the compression data stream.
- *
- * @returns iprt status code.
- * @param   pZip        The compressor instance.
- */
-RTDECL(int)     RTZipCompFinish(PRTZIPCOMP pZip)
-{
-    return pZip->pfnFinish(pZip);
-}
-RT_EXPORT_SYMBOL(RTZipCompFinish);
-
-
-/**
- * Destroys the compressor instance.
- *
- * @returns iprt status code.
- * @param   pZip        The compressor instance.
- */
-RTDECL(int)     RTZipCompDestroy(PRTZIPCOMP pZip)
-{
-    /*
-     * Compressor specific destruction attempt first.
-     */
-    int rc = pZip->pfnDestroy(pZip);
-    AssertRCReturn(rc, rc);
-
-    /*
-     * Free the instance memory.
-     */
-    pZip->enmType = RTZIPTYPE_INVALID;
-    RTMemFree(pZip);
-    return VINF_SUCCESS;
-}
-RT_EXPORT_SYMBOL(RTZipCompDestroy);
-
-
-/**
- * @copydoc RTZipDecompress
- */
-static DECLCALLBACK(int) rtZipStubDecompress(PRTZIPDECOMP pZip, void *pvBuf, size_t cbBuf, size_t *pcbWritten)
-{
-    return VERR_NOT_SUPPORTED;
-}
-
-
-/**
- * @copydoc RTZipDecompDestroy
- */
-static DECLCALLBACK(int) rtZipStubDecompDestroy(PRTZIPDECOMP pZip)
-{
-    return VINF_SUCCESS;
-}
-
-
-/**
- * Create a decompressor instance.
- *
- * @returns iprt status code.
- * @param   ppZip       Where to store the instance handle.
- * @param   pvUser      User argument which will be passed on to pfnOut and pfnIn.
- * @param   pfnIn       Callback for producing input for decompression.
- */
-RTDECL(int)     RTZipDecompCreate(PRTZIPDECOMP *ppZip, void *pvUser, PFNRTZIPIN pfnIn)
-{
-    /*
-     * Validate input.
-     */
-    AssertPtrReturn(pfnIn, VERR_INVALID_POINTER);
-    AssertPtrReturn(ppZip, VERR_INVALID_POINTER);
-
-    /*
-     * Allocate memory for the instance data.
-     */
-    PRTZIPDECOMP pZip = (PRTZIPDECOMP)RTMemAlloc(sizeof(RTZIPDECOMP));
-    if (!pZip)
-        return VERR_NO_MEMORY;
-
-    /*
-     * Init instance.
-     */
-    pZip->pfnIn   = pfnIn;
-    pZip->enmType = RTZIPTYPE_INVALID;
-    pZip->pvUser  = pvUser;
-    pZip->pfnDecompress = NULL;
-    pZip->pfnDestroy = rtZipStubDecompDestroy;
-
-    *ppZip = pZip;
-    return VINF_SUCCESS;
-}
-RT_EXPORT_SYMBOL(RTZipDecompCreate);
-
-
-/**
- * Lazy init of the decompressor.
- * @returns iprt status code.
- * @param   pZip        The decompressor instance.
- */
-static int rtzipDecompInit(PRTZIPDECOMP pZip)
-{
-    /*
-     * Read the first byte from the stream so we can determine the type.
-     */
-    uint8_t u8Type;
-    int rc = pZip->pfnIn(pZip->pvUser, &u8Type, sizeof(u8Type), NULL);
-    if (RT_FAILURE(rc))
-        return rc;
-
-    /*
-     * Determine type and do type specific init.
-     */
-    pZip->enmType = (RTZIPTYPE)u8Type;
-    rc = VERR_NOT_SUPPORTED;
-    switch (pZip->enmType)
-    {
-        case RTZIPTYPE_STORE:
-#ifdef RTZIP_USE_STORE
-            rc = rtZipStoreDecompInit(pZip);
-#else
-            AssertMsgFailed(("Store is not include in this build!\n"));
-#endif
-            break;
-
-        case RTZIPTYPE_ZLIB:
-#ifdef RTZIP_USE_ZLIB
-            rc = rtZipZlibDecompInit(pZip);
-#else
-            AssertMsgFailed(("Zlib is not include in this build!\n"));
-#endif
-            break;
-
-        case RTZIPTYPE_BZLIB:
-#ifdef RTZIP_USE_BZLIB
-            rc = rtZipBZlibDecompInit(pZip);
-#else
-            AssertMsgFailed(("BZlib is not include in this build!\n"));
-#endif
-            break;
-
-        case RTZIPTYPE_LZF:
-#ifdef RTZIP_USE_LZF
-            rc = rtZipLZFDecompInit(pZip);
-#else
-            AssertMsgFailed(("LZF is not include in this build!\n"));
-#endif
-            break;
-
-        case RTZIPTYPE_LZJB:
-#ifdef RTZIP_USE_LZJB
-            AssertMsgFailed(("LZJB streaming support is not implemented yet!\n"));
-#else
-            AssertMsgFailed(("LZJB is not include in this build!\n"));
-#endif
-            break;
-
-        case RTZIPTYPE_LZO:
-#ifdef RTZIP_USE_LZJB
-            AssertMsgFailed(("LZO streaming support is not implemented yet!\n"));
-#else
-            AssertMsgFailed(("LZO is not include in this build!\n"));
-#endif
-            break;
-
-        default:
-            AssertMsgFailed(("Invalid compression type %d (%#x)!\n", pZip->enmType, pZip->enmType));
-            rc = VERR_INVALID_MAGIC;
-            break;
-    }
-    if (RT_FAILURE(rc))
-    {
-        pZip->pfnDecompress = rtZipStubDecompress;
-        pZip->pfnDestroy = rtZipStubDecompDestroy;
-    }
-
-    return rc;
-}
-
-
-/**
- * Decompresses a chunk of memory.
- *
- * @returns iprt status code.
- * @param   pZip        The decompressor instance.
- * @param   pvBuf       Where to store the decompressed data.
- * @param   cbBuf       Number of bytes to produce. If pcbWritten is set
- *                      any number of bytes up to cbBuf might be returned.
- * @param   pcbWritten  Number of bytes actually written to the buffer. If NULL
- *                      cbBuf number of bytes must be written.
- */
-RTDECL(int)     RTZipDecompress(PRTZIPDECOMP pZip, void *pvBuf, size_t cbBuf, size_t *pcbWritten)
-{
-    /*
-     * Skip empty requests.
-     */
-    if (!cbBuf)
-        return VINF_SUCCESS;
-
-    /*
-     * Lazy init.
-     */
-    if (!pZip->pfnDecompress)
-    {
-        int rc = rtzipDecompInit(pZip);
-        if (RT_FAILURE(rc))
-            return rc;
-    }
-
-    /*
-     * 'Read' the decompressed stream.
-     */
-    return pZip->pfnDecompress(pZip, pvBuf, cbBuf, pcbWritten);
-}
-RT_EXPORT_SYMBOL(RTZipDecompress);
-
-
-/**
- * Destroys the decompressor instance.
- *
- * @returns iprt status code.
- * @param   pZip        The decompressor instance.
- */
-RTDECL(int)     RTZipDecompDestroy(PRTZIPDECOMP pZip)
-{
-    /*
-     * Destroy compressor instance and flush the output buffer.
-     */
-    int rc = pZip->pfnDestroy(pZip);
-    AssertRCReturn(rc, rc);
-
-    /*
-     * Free the instance memory.
-     */
-    pZip->enmType = RTZIPTYPE_INVALID;
-    RTMemFree(pZip);
-    return rc;
-}
-RT_EXPORT_SYMBOL(RTZipDecompDestroy);
-
-
-RTDECL(int) RTZipBlockCompress(RTZIPTYPE enmType, RTZIPLEVEL enmLevel, uint32_t fFlags,
-                               void const *pvSrc, size_t cbSrc,
-                               void *pvDst, size_t cbDst, size_t *pcbDstActual) RT_NO_THROW
-{
-    /* input validation - the crash and burn approach as speed is essential here. */
-    Assert(enmLevel <= RTZIPLEVEL_MAX && enmLevel >= RTZIPLEVEL_STORE);
-    Assert(!fFlags);
-
-    /*
-     * Deal with flags involving prefixes.
-     */
-    /** @todo later: type and/or compressed length prefix. */
-
-    /*
-     * The type specific part.
-     */
-    switch (enmType)
-    {
-        case RTZIPTYPE_LZF:
-        {
-#ifdef RTZIP_USE_LZF
-# if 0
-            static const uint8_t s_abZero4K[] =
-            {
-                0x01, 0x00, 0x00, 0xe0, 0xff, 0x00, 0xe0, 0xff,
-                0x00, 0xe0, 0xff, 0x00, 0xe0, 0xff, 0x00, 0xe0,
-                0xff, 0x00, 0xe0, 0xff, 0x00, 0xe0, 0xff, 0x00,
-                0xe0, 0xff, 0x00, 0xe0, 0xff, 0x00, 0xe0, 0xff,
-                0x00, 0xe0, 0xff, 0x00, 0xe0, 0xff, 0x00, 0xe0,
-                0xff, 0x00, 0xe0, 0xff, 0x00, 0xe0, 0xff, 0x00,
-                0xe0, 0x7d, 0x00
-            };
-            if (    cbSrc == _4K
-                &&  !((uintptr_t)pvSrc & 15)
-                &&  ASMMemIsZeroPage(pvSrc))
-            {
-                if (RT_UNLIKELY(cbDst < sizeof(s_abZero4K)))
-                    return VERR_BUFFER_OVERFLOW;
-                memcpy(pvDst, s_abZero4K, sizeof(s_abZero4K));
-                *pcbDstActual = sizeof(s_abZero4K);
-                break;
-            }
-# endif
-
-            unsigned cbDstActual = lzf_compress(pvSrc, (unsigned)cbSrc, pvDst, (unsigned)cbDst);    /** @todo deal with size type overflows */
-            if (RT_UNLIKELY(cbDstActual < 1))
-                return VERR_BUFFER_OVERFLOW;
-            *pcbDstActual = cbDstActual;
-            break;
-#else
-            return VERR_NOT_SUPPORTED;
-#endif
-        }
-
-        case RTZIPTYPE_STORE:
-        {
-            if (cbDst < cbSrc)
-                return VERR_BUFFER_OVERFLOW;
-            memcpy(pvDst, pvSrc, cbSrc);
-            *pcbDstActual = cbSrc;
-            break;
-        }
-
-        case RTZIPTYPE_LZJB:
-        {
-#ifdef RTZIP_USE_LZJB
-            AssertReturn(cbDst > cbSrc, VERR_BUFFER_OVERFLOW);
-            size_t cbDstActual = lzjb_compress((void *)pvSrc, (uint8_t *)pvDst + 1, cbSrc, cbSrc, 0 /*??*/);
-            if (cbDstActual == cbSrc)
-                *(uint8_t *)pvDst = 0;
-            else
-                *(uint8_t *)pvDst = 1;
-            *pcbDstActual = cbDstActual + 1;
-            break;
-#else
-            return VERR_NOT_SUPPORTED;
-#endif
-        }
-
-        case RTZIPTYPE_LZO:
-        {
-#ifdef RTZIP_USE_LZO
-            uint64_t Scratch[RT_ALIGN(LZO1X_1_MEM_COMPRESS, sizeof(uint64_t)) / sizeof(uint64_t)];
-            int rc = lzo_init();
-            if (RT_UNLIKELY(rc != LZO_E_OK))
-                return VERR_INTERNAL_ERROR;
-
-            lzo_uint cbDstInOut = cbDst;
-            rc = lzo1x_1_compress((const lzo_bytep)pvSrc, cbSrc, (lzo_bytep )pvDst, &cbDstInOut, &Scratch[0]);
-            if (RT_UNLIKELY(rc != LZO_E_OK))
-                switch (rc)
-                {
-                    case LZO_E_OUTPUT_OVERRUN:  return VERR_BUFFER_OVERFLOW;
-                    default:                    return VERR_GENERAL_FAILURE;
-                }
-            *pcbDstActual = cbDstInOut;
-            break;
-#else
-            return VERR_NOT_SUPPORTED;
-#endif
-        }
-
-        case RTZIPTYPE_ZLIB:
-        case RTZIPTYPE_BZLIB:
-            return VERR_NOT_SUPPORTED;
-
-        default:
-            AssertMsgFailed(("%d\n", enmType));
-            return VERR_INVALID_PARAMETER;
-    }
-
-    return VINF_SUCCESS;
-}
-RT_EXPORT_SYMBOL(RTZipBlockCompress);
-
-
-RTDECL(int) RTZipBlockDecompress(RTZIPTYPE enmType, uint32_t fFlags,
-                                 void const *pvSrc, size_t cbSrc, size_t *pcbSrcActual,
-                                 void *pvDst, size_t cbDst, size_t *pcbDstActual) RT_NO_THROW
-{
-    /* input validation - the crash and burn approach as speed is essential here. */
-    Assert(!fFlags);
-
-    /*
-     * Deal with flags involving prefixes.
-     */
-    /** @todo later: type and/or compressed length prefix. */
-
-    /*
-     * The type specific part.
-     */
-    switch (enmType)
-    {
-        case RTZIPTYPE_LZF:
-        {
-#ifdef RTZIP_USE_LZF
-            unsigned cbDstActual = lzf_decompress(pvSrc, (unsigned)cbSrc, pvDst, (unsigned)cbDst);  /** @todo deal with size type overflows */
-            if (RT_UNLIKELY(cbDstActual < 1))
-            {
-                if (errno == E2BIG)
-                    return VERR_BUFFER_OVERFLOW;
-                Assert(errno == EINVAL);
-                return VERR_GENERAL_FAILURE;
-            }
-            if (pcbDstActual)
-                *pcbDstActual = cbDstActual;
-            if (pcbSrcActual)
-                *pcbSrcActual = cbSrc;
-            break;
-#else
-            return VERR_NOT_SUPPORTED;
-#endif
-        }
-
-        case RTZIPTYPE_STORE:
-        {
-            if (cbDst < cbSrc)
-                return VERR_BUFFER_OVERFLOW;
-            memcpy(pvDst, pvSrc, cbSrc);
-            if (pcbDstActual)
-                *pcbDstActual = cbSrc;
-            if (pcbSrcActual)
-                *pcbSrcActual = cbSrc;
-            break;
-        }
-
-        case RTZIPTYPE_LZJB:
-        {
-#ifdef RTZIP_USE_LZJB
-            if (*(uint8_t *)pvSrc == 1)
-            {
-                int rc = lzjb_decompress((uint8_t *)pvSrc + 1, pvDst, cbSrc - 1, cbDst, 0 /*??*/);
-                if (RT_UNLIKELY(rc != 0))
-                    return VERR_GENERAL_FAILURE;
-                if (pcbDstActual)
-                    *pcbDstActual = cbDst;
-            }
-            else
-            {
-                AssertReturn(cbDst >= cbSrc - 1, VERR_BUFFER_OVERFLOW);
-                memcpy(pvDst, (uint8_t *)pvSrc + 1, cbSrc - 1);
-                if (pcbDstActual)
-                    *pcbDstActual = cbSrc - 1;
-            }
-            if (pcbSrcActual)
-                *pcbSrcActual = cbSrc;
-            break;
-#else
-            return VERR_NOT_SUPPORTED;
-#endif
-        }
-
-        case RTZIPTYPE_LZO:
-        {
-#ifdef RTZIP_USE_LZO
-            int rc = lzo_init();
-            if (RT_UNLIKELY(rc != LZO_E_OK))
-                return VERR_INTERNAL_ERROR;
-            lzo_uint cbDstInOut = cbDst;
-            rc = lzo1x_decompress((const lzo_bytep)pvSrc, cbSrc, (lzo_bytep)pvDst, &cbDstInOut, NULL);
-            if (RT_UNLIKELY(rc != LZO_E_OK))
-                switch (rc)
-                {
-                    case LZO_E_OUTPUT_OVERRUN:  return VERR_BUFFER_OVERFLOW;
-                    default:
-                    case LZO_E_INPUT_OVERRUN:   return VERR_GENERAL_FAILURE;
-                }
-            if (pcbSrcActual)
-                *pcbSrcActual = cbSrc;
-            if (pcbDstActual)
-                *pcbDstActual = cbDstInOut;
-            break;
-#else
-            return VERR_NOT_SUPPORTED;
-#endif
-        }
-
-        case RTZIPTYPE_ZLIB:
-        case RTZIPTYPE_BZLIB:
-            return VERR_NOT_SUPPORTED;
-
-        default:
-            AssertMsgFailed(("%d\n", enmType));
-            return VERR_INVALID_PARAMETER;
-    }
-    return VINF_SUCCESS;
-}
-RT_EXPORT_SYMBOL(RTZipBlockDecompress);
-
