Chromium Code Reviews| Index: chrome/common/zip_internal.cc |
| diff --git a/chrome/common/zip_internal.cc b/chrome/common/zip_internal.cc |
| index ddcfd00a360fb1d01383d27f04aa75669e92d7f5..9d693ddd4e6c9d8b008121ea1dd15239f7c7be4f 100644 |
| --- a/chrome/common/zip_internal.cc |
| +++ b/chrome/common/zip_internal.cc |
| @@ -9,6 +9,8 @@ |
| #include "third_party/zlib/contrib/minizip/zip.h" |
| #if defined(OS_WIN) |
| #include "third_party/zlib/contrib/minizip/iowin32.h" |
| +#elif defined(OS_POSIX) |
| +#include "third_party/zlib/contrib/minizip/ioapi.h" |
| #endif |
| namespace { |
| @@ -65,6 +67,42 @@ void* ZipOpenFunc(void *opaque, const char* filename, int mode) { |
| } |
| #endif |
| +#if defined(OS_POSIX) |
| +void* fdopen_file_func(void* opaque, const char* filename, int mode) { |
|
satorux1
2011/12/15 00:05:36
Since the code is now in Chrome codebase, the func
Jorge Lucangeli Obes
2011/12/15 00:19:00
Done.
|
| + FILE* file = NULL; |
|
satorux1
2011/12/15 00:05:36
And the indentation is 2, instead of 4.
Jorge Lucangeli Obes
2011/12/15 00:19:00
Done.
|
| + const char* mode_fopen = NULL; |
| + |
| + if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ) |
| + mode_fopen = "rb"; |
| + else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) |
| + mode_fopen = "r+b"; |
| + else if (mode & ZLIB_FILEFUNC_MODE_CREATE) |
| + mode_fopen = "wb"; |
| + |
| + if ((filename != NULL) && (mode_fopen != NULL)) |
| + file = fdopen(*static_cast<int*>(opaque), mode_fopen); |
| + |
| + return file; |
| +} |
| + |
| +// We don't actually close the file stream since that would close |
| +// the underlying file descriptor, and we don't own it. We do free |
| +// |opaque| since we malloc'ed in fill_fdopen_filefunc. |
| +int fclose_file_func(void* opaque, void* stream) { |
| + free(opaque); |
| + return 0; |
| +} |
| + |
| +void fill_fdopen_filefunc(zlib_filefunc_def* pzlib_filefunc_def, int fd) { |
| + fill_fopen_filefunc(pzlib_filefunc_def); |
| + pzlib_filefunc_def->zopen_file = fdopen_file_func; |
| + pzlib_filefunc_def->zclose_file = fclose_file_func; |
| + int* ptr_fd = static_cast<int*>(malloc(sizeof(fd))); |
| + *ptr_fd = fd; |
| + pzlib_filefunc_def->opaque = ptr_fd; |
| +} |
| +#endif // defined(OS_POSIX) |
| + |
| } // namespace |
| namespace zip { |
| @@ -81,6 +119,15 @@ unzFile OpenForUnzipping(const std::string& file_name_utf8) { |
| return unzOpen2(file_name_utf8.c_str(), zip_func_ptrs); |
| } |
| +#if defined(OS_POSIX) |
| +unzFile OpenFdForUnzipping(int zip_fd) { |
| + zlib_filefunc_def zip_funcs; |
| + fill_fdopen_filefunc(&zip_funcs, zip_fd); |
| + // Passing dummy "fd" filename to zlib. |
| + return unzOpen2("fd", &zip_funcs); |
| +} |
| +#endif |
| + |
| zipFile OpenForZipping(const std::string& file_name_utf8, int append_flag) { |
| zlib_filefunc_def* zip_func_ptrs = NULL; |
| #if defined(OS_WIN) |