Changeset 47516 in vbox for trunk/src/VBox/Runtime/common/zip
- Timestamp:
- Aug 1, 2013 6:33:39 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/zip/zip.cpp
r47500 r47516 616 616 } 617 617 618 /**619 * pZip->u.Zlib.avail_in must be correctly initialized before620 * calling this function621 * pZip->u.Zlib.next_in must be correctly initialized before622 * calling this function623 *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 the628 * buffer629 *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 do642 {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 }658 618 659 619 /** … … 1677 1637 } 1678 1638 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_ZLIB1688 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 #else1698 AssertMsgFailed(("Zlib is not include in this build!\n"));1699 #endif1700 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 the1718 * buffer1719 * @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 the1722 * 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);1759 1639 1760 1640 /**
Note:
See TracChangeset
for help on using the changeset viewer.