VirtualBox

Ignore:
Timestamp:
Aug 1, 2013 6:33:39 PM (11 years ago)
Author:
vboxsync
Message:

Backed out r87679: Still working on the wrong solution... Sigh.

File:
1 edited

Legend:

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

    r47500 r47516  
    616616}
    617617
    618 /**
    619  * pZip->u.Zlib.avail_in must be correctly initialized before
    620  * calling this function
    621  * pZip->u.Zlib.next_in must be correctly initialized before
    622  * calling this function
    623  * 
    624  * @param pZip The decompressor instance.
    625  * @param pvBufOut    Where to store the decompressed data.
    626  * @param cbBufOut    Number of bytes to produce.
    627  * @param pcbWritten  Number of bytes actually written to the
    628  *                    buffer
    629  *
    630  * @return iprt status code.
    631  */
    632 static DECLCALLBACK(int) rtZipZlibBufferDecompress(PRTZIPDECOMP pZip, void *pvBufOut, size_t cbBufOut, size_t *pcbWritten)
    633 {
    634     int rc = VINF_SUCCESS;
    635     pZip->u.Zlib.next_out = (Bytef *)pvBufOut;
    636     pZip->u.Zlib.avail_out = (uInt)cbBufOut;
    637     int sh = pZip->u.Zlib.avail_out;
    638 
    639     *pcbWritten = 0;
    640 
    641     do
    642     {
    643         rc = inflate(&pZip->u.Zlib, Z_SYNC_FLUSH);
    644 
    645         if (rc != Z_OK && rc != Z_STREAM_END)
    646         {
    647             rc = zipErrConvertFromZlib(rc, false /*fCompressing*/);
    648             break;
    649         }
    650 
    651         *pcbWritten += (sh - pZip->u.Zlib.avail_out);
    652         sh = pZip->u.Zlib.avail_out;
    653     }
    654     while (pZip->u.Zlib.avail_out > 0 && pZip->u.Zlib.avail_in > 0 );
    655 
    656     return rc;
    657 }
    658618
    659619/**
     
    16771637}
    16781638
    1679 /**
    1680  * Lazy init of the decompressor for the Gzip file.
    1681  * @return iprt status code.
    1682  * @param   pZip  The decompressor instance.
    1683  */
    1684 static int rtzipGzipFileDecompInit(PRTZIPDECOMP pZip)
    1685 {
    1686     int rc = 0;
    1687 #ifdef RTZIP_USE_ZLIB
    1688     pZip->pfnDecompress = rtZipZlibBufferDecompress;
    1689     pZip->pfnDestroy = rtZipZlibDecompDestroy;
    1690 
    1691     memset(&pZip->u.Zlib, 0, sizeof(pZip->u.Zlib));
    1692     pZip->enmType = RTZIPTYPE_ZLIB;
    1693     pZip->u.Zlib.opaque    = pZip;
    1694 
    1695     rc = inflateInit2(&pZip->u.Zlib, MAX_WBITS + 16 /* autodetect gzip header */);
    1696     rc >= 0 ? VINF_SUCCESS : zipErrConvertFromZlib(rc, false /*fCompressing*/);
    1697 #else
    1698     AssertMsgFailed(("Zlib is not include in this build!\n"));
    1699 #endif
    1700 
    1701     if (RT_FAILURE(rc))
    1702     {
    1703         pZip->pfnDecompress = rtZipStubDecompress;
    1704         pZip->pfnDestroy = rtZipStubDecompDestroy;
    1705     }
    1706 
    1707     return rc;
    1708 }
    1709 
    1710 /**
    1711  * Decompresses a chunk of Gzip file.
    1712  *
    1713  * @returns iprt status code.
    1714  * @param   pZip        The stream decompressor instance.
    1715  * @param   pvBufIn     Where to read the compressed data from.
    1716  * @param   cbBufIn     Number of bytes to read.
    1717  * @param   pcbRead     Number of bytes actually read from the
    1718  *                      buffer
    1719  * @param   pvBufOut    Where to store the decompressed data.
    1720  * @param   cbBufOut    Number of bytes to produce.
    1721  * @param   pcbWritten  Number of bytes actually written to the
    1722  *                      buffer.
    1723  */
    1724 RTDECL(int)     RTZipGzipFileBufferDecompress(PRTZIPDECOMP pZip,
    1725                                         void *pvBufIn,
    1726                                         size_t cbBufIn,
    1727                                         size_t *pcbRead,
    1728                                         void *pvBufOut,
    1729                                         size_t cbBufOut,
    1730                                         size_t *pcbWritten)
    1731 {
    1732     int rc;
    1733     /*
    1734      * Skip empty requests.
    1735      */
    1736     if (!cbBufIn)
    1737         return VINF_SUCCESS;
    1738 
    1739     if (!pZip->pfnDecompress)
    1740     {
    1741         rc = rtzipGzipFileDecompInit(pZip);
    1742         if (RT_FAILURE(rc))
    1743             return rc;
    1744     }
    1745 
    1746     pZip->u.Zlib.avail_in = (uInt)cbBufIn;
    1747     pZip->u.Zlib.next_in = (Bytef *)pvBufIn;
    1748 
    1749     /*
    1750      * 'Read' the decompressed stream.
    1751      */
    1752     rc = pZip->pfnDecompress(pZip, pvBufOut, cbBufOut, pcbWritten);
    1753 
    1754     *pcbRead = cbBufIn - pZip->u.Zlib.avail_in;
    1755 
    1756     return rc;
    1757 }
    1758 RT_EXPORT_SYMBOL(RTZipGzipFileBufferDecompress);
    17591639
    17601640/**
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