From c162a3620a3d0d317f59af8ddc2d1605bf5ee4b3 Mon Sep 17 00:00:00 2001
From: martell <martellmalone@gmail.com>
Date: Sat, 11 Oct 2014 03:32:38 +0100
Subject: [PATCH 1/3] unzip: add function unzOpenBuffer

---
 unzip.c     | 11 +++++++++++
 unzip.h     |  2 ++
 2 files changed, 13 insertions(+)

diff --git a/unzip.c b/unzip.c
index 11030cb..1f4bdda 100644
--- a/unzip.c
+++ b/unzip.c
@@ -29,6 +29,7 @@
 
 #include "zlib.h"
 #include "unzip.h"
+#include "ioapi_mem.h"
 
 #ifdef HAVE_AES
 #  define AES_METHOD          (99)
@@ -553,6 +554,16 @@ extern unzFile ZEXPORT unzOpen64(const void *path)
     return unzOpenInternal(path, NULL);
 }
 
+extern unzFile ZEXPORT unzOpenBuffer(const  void* buffer, uLong size)
+{
+    char path[48] = {0};
+    ourmemory_t FileMemory;
+    zlib_filefunc64_32_def memory_file;
+    sprintf(path, "%llx %lx", (unsigned long long)buffer, (unsigned long)size);
+    fill_memory_filefunc(&memory_file, &FileMemory);
+    return unzOpenInternal(path, &memory_file);
+}
+
 extern int ZEXPORT unzClose(unzFile file)
 {
     unz64_s *s;
diff --git a/unzip.h b/unzip.h
index 1aa197f..8503471 100644
--- a/unzip.h
+++ b/unzip.h
@@ -131,6 +131,8 @@ extern unzFile ZEXPORT unzOpen64(const void *path);
    open64_file_func callback. Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path 
    is a pointer to a wide unicode string  (LPCTSTR is LPCWSTR), so const char *does not describe the reality */
 
+extern unzFile ZEXPORT unzOpenBuffer OF((const void* buffer, uLong size));
+/* Open a Zip file, like unzOpen, but from a buffer */
 extern unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def);
 /* Open a Zip file, like unzOpen, but provide a set of file low level API for read/write operations */
 extern unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def);
-- 
2.1.2
