aboutsummaryrefslogtreecommitdiffstats
path: root/minzip
diff options
context:
space:
mode:
Diffstat (limited to 'minzip')
-rw-r--r--minzip/Zip.c37
-rw-r--r--minzip/Zip.h7
2 files changed, 44 insertions, 0 deletions
diff --git a/minzip/Zip.c b/minzip/Zip.c
index 8cdb898..46d2f82 100644
--- a/minzip/Zip.c
+++ b/minzip/Zip.c
@@ -810,6 +810,43 @@ bool mzExtractZipEntryToFile(const ZipArchive *pArchive,
return true;
}
+typedef struct {
+ unsigned char* buffer;
+ long len;
+} BufferExtractCookie;
+
+static bool bufferProcessFunction(const unsigned char *data, int dataLen,
+ void *cookie) {
+ BufferExtractCookie *bec = (BufferExtractCookie*)cookie;
+
+ memmove(bec->buffer, data, dataLen);
+ bec->buffer += dataLen;
+ bec->len -= dataLen;
+
+ return true;
+}
+
+/*
+ * Uncompress "pEntry" in "pArchive" to buffer, which must be large
+ * enough to hold mzGetZipEntryUncomplen(pEntry) bytes.
+ */
+bool mzExtractZipEntryToBuffer(const ZipArchive *pArchive,
+ const ZipEntry *pEntry, unsigned char *buffer)
+{
+ BufferExtractCookie bec;
+ bec.buffer = buffer;
+ bec.len = mzGetZipEntryUncompLen(pEntry);
+
+ bool ret = mzProcessZipEntryContents(pArchive, pEntry,
+ bufferProcessFunction, (void*)&bec);
+ if (!ret || bec.len != 0) {
+ LOGE("Can't extract entry to memory buffer.\n");
+ return false;
+ }
+ return true;
+}
+
+
/* Helper state to make path translation easier and less malloc-happy.
*/
typedef struct {
diff --git a/minzip/Zip.h b/minzip/Zip.h
index 1c1df2f..9f99fba 100644
--- a/minzip/Zip.h
+++ b/minzip/Zip.h
@@ -169,6 +169,13 @@ bool mzExtractZipEntryToFile(const ZipArchive *pArchive,
const ZipEntry *pEntry, int fd);
/*
+ * Inflate and write an entry to a memory buffer, which must be long
+ * enough to hold mzGetZipEntryUncomplen(pEntry) bytes.
+ */
+bool mzExtractZipEntryToBuffer(const ZipArchive *pArchive,
+ const ZipEntry *pEntry, unsigned char* buffer);
+
+/*
* Inflate all entries under zipDir to the directory specified by
* targetDir, which must exist and be a writable directory.
*