VirtualBox

Changeset 21800 in vbox


Ignore:
Timestamp:
Jul 26, 2009 3:51:06 PM (16 years ago)
Author:
vboxsync
Message:

zip.cpp: do LZF block by block.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/zip.cpp

    r21337 r21800  
    55
    66/*
    7  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     7 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3737//#define RTZIP_USE_BZLIB 1
    3838#define RTZIP_USE_LZF 1
     39#define RTZIP_LZF_BLOCK_BY_BLOCK
    3940
    4041
     
    224225        struct
    225226        {
     227# ifndef RTZIP_LZF_BLOCK_BY_BLOCK
    226228            /** Current input buffer postition. */
    227229            uint8_t    *pbInput;
    228230            /** The number of bytes left in the input buffer. */
    229231            size_t      cbInput;
     232# endif
    230233            /** The spill buffer.
    231234             * LZF is a block based compressor and not a stream compressor. So,
     
    10801083     * not possible we'll use the spill buffer.
    10811084     */
     1085# ifdef RTZIP_LZF_BLOCK_BY_BLOCK
     1086    size_t cbWritten = 0;
     1087    while (cbBuf > 0)
     1088    {
     1089        /*
     1090         * Anything in the spill buffer?
     1091         */
     1092        if (pZip->u.LZF.cbSpill > 0)
     1093        {
     1094            unsigned cb = (unsigned)RT_MIN(pZip->u.LZF.cbSpill, cbBuf);
     1095            memcpy(pvBuf, pZip->u.LZF.pbSpill, cb);
     1096            pZip->u.LZF.pbSpill += cb;
     1097            pZip->u.LZF.cbSpill -= cb;
     1098            cbWritten += cb;
     1099            cbBuf -= cb;
     1100            if (!cbBuf)
     1101                break;
     1102            pvBuf = (uint8_t *)pvBuf + cb;
     1103        }
     1104
     1105        /*
     1106         * We always read and work one block at a time.
     1107         */
     1108        RTZIPLZFHDR Hdr;
     1109        int rc = pZip->pfnIn(pZip->pvUser, &Hdr, sizeof(Hdr), NULL);
     1110        if (RT_FAILURE(rc))
     1111            return rc;
     1112        if (!rtZipLZFValidHeader(&Hdr))
     1113            return VERR_GENERAL_FAILURE; /** @todo Get better error codes for RTZip! */
     1114        if (Hdr.cbData > 0)
     1115        {
     1116            rc = pZip->pfnIn(pZip->pvUser, &pZip->abBuffer[0], Hdr.cbData, NULL);
     1117            if (RT_FAILURE(rc))
     1118                return rc;
     1119        }
     1120
     1121        /*
     1122         * Does the uncompressed data fit into the supplied buffer?
     1123         * If so we uncompress it directly into the user buffer, else we'll have to use the spill buffer.
     1124         */
     1125        unsigned cbUncompressed = Hdr.cbUncompressed;
     1126        if (cbUncompressed <= cbBuf)
     1127        {
     1128            unsigned cbOutput = lzf_decompress(&pZip->abBuffer[0], Hdr.cbData, pvBuf, cbUncompressed);
     1129            if (cbOutput != cbUncompressed)
     1130            {
     1131                AssertMsgFailed(("Decompression error, errno=%d. cbOutput=%#x cbUncompressed=%#x\n",
     1132                                 errno, cbOutput, cbUncompressed));
     1133                return VERR_GENERAL_FAILURE; /** @todo Get better error codes for RTZip! */
     1134            }
     1135            cbBuf -= cbUncompressed;
     1136            pvBuf = (uint8_t *)pvBuf + cbUncompressed;
     1137            cbWritten += cbUncompressed;
     1138        }
     1139        else
     1140        {
     1141            unsigned cbOutput = lzf_decompress(&pZip->abBuffer[0], Hdr.cbData, pZip->u.LZF.abSpill, cbUncompressed);
     1142            if (cbOutput != cbUncompressed)
     1143            {
     1144                AssertMsgFailed(("Decompression error, errno=%d. cbOutput=%#x cbUncompressed=%#x\n",
     1145                                 errno, cbOutput, cbUncompressed));
     1146                return VERR_GENERAL_FAILURE; /** @todo Get better error codes for RTZip! */
     1147            }
     1148            pZip->u.LZF.pbSpill = &pZip->u.LZF.abSpill[0];
     1149            pZip->u.LZF.cbSpill = cbUncompressed;
     1150        }
     1151    }
     1152
     1153    if (pcbWritten)
     1154        *pcbWritten = cbWritten;
     1155# else  /* !RTZIP_LZF_BLOCK_BY_BLOCK */
    10821156    while (cbBuf > 0)
    10831157    {
     
    12001274            *pcbWritten += cbUncompressed;
    12011275    }
    1202 
     1276# endif /* !RTZIP_LZF_BLOCK_BY_BLOCK */
    12031277    return VINF_SUCCESS;
    12041278}
     
    12241298    pZip->pfnDestroy = rtZipLZFDecompDestroy;
    12251299
     1300# ifndef RTZIP_LZF_BLOCK_BY_BLOCK
    12261301    pZip->u.LZF.pbInput    = NULL;
    12271302    pZip->u.LZF.cbInput    = 0;
     1303# endif
    12281304    pZip->u.LZF.cbSpill    = 0;
    12291305    pZip->u.LZF.pbSpill    = NULL;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette