Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Unified Diff: third_party/zlib/google/zip.h

Issue 179963002: New Zip::ZipFromMemory API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixup! New Zip::ZipFromMemory API. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/zlib/google/zip.h
diff --git a/third_party/zlib/google/zip.h b/third_party/zlib/google/zip.h
index 9809fce2bfb1b5f7092a65ac36eac4e291e17440..f93b595131e51d9769630e80cfa8e286c5fc8204 100644
--- a/third_party/zlib/google/zip.h
+++ b/third_party/zlib/google/zip.h
@@ -5,9 +5,16 @@
#ifndef THIRD_PARTY_ZLIB_GOOGLE_ZIP_H_
#define THIRD_PARTY_ZLIB_GOOGLE_ZIP_H_
+#include <map>
+#include <vector>
+
#include "base/callback.h"
#include "base/files/file_path.h"
+namespace base {
+class RefCountedMemory;
+}
+
namespace zip {
// Zip the contents of src_dir into dest_file. src_path must be a directory.
@@ -36,6 +43,32 @@ bool ZipFiles(const base::FilePath& src_dir,
int dest_fd);
#endif // defined(OS_POSIX)
+// Adds to |zip_file| files using contents from memory. |zip_file| is created if
+// it does not exist. |files| contains a map with the file path to
+// be stored in the zip file plus its contents. The FilePath in |files| may not
+// be empty, absolute or contain a '..' component, else the function fails.
+// The paths must therefore be relative and preferably canonicalized.
+// Calling this with an empty |files| has no effect.
+//
+// If |append| is true, the new files are appended to an already existing file,
+// if any. Else, the file is recreated from scratch, meaning, all previous
+// contents are deleted without the possibility of recovery.
+//
+// If the RefCountedMemory in |files| is NULL, the file is removed from the zip
+// archive. If the RefCountedMemory in |files| is not NULL, a file will be
+// created with those contents. The contents can have a size of 0 bytes.
+// Note: the data passed in |files| is copied. This function does not keep any
+// references to the original data after it returns.
+//
+// If the FilePath ends with a path separator (a slash), a folder is created.
+// Note: the contents for a folder must be either NULL or 0-byte big, so the
+// folder will be removed or added, respectively.
+typedef std::map<base::FilePath, scoped_refptr<base::RefCountedMemory> >
+ ZipContents;
+bool ZipFromMemory(const base::FilePath& zip_path,
satorux1 2014/02/26 04:05:47 I think it's not a good idea to add new APIs in th
João Eiras 2014/02/26 17:35:38 Which APIs would belong there then ? All the zip::
satorux1 2014/02/27 06:57:00 Here's what I meant: 1) zip.h just contains a bun
+ const ZipContents& files,
+ bool append);
+
// Unzip the contents of zip_file into dest_dir.
bool Unzip(const base::FilePath& zip_file, const base::FilePath& dest_dir);

Powered by Google App Engine
This is Rietveld 408576698