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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef THIRD_PARTY_ZLIB_GOOGLE_ZIP_H_ 5 #ifndef THIRD_PARTY_ZLIB_GOOGLE_ZIP_H_
6 #define THIRD_PARTY_ZLIB_GOOGLE_ZIP_H_ 6 #define THIRD_PARTY_ZLIB_GOOGLE_ZIP_H_
7 7
8 #include <map>
9 #include <vector>
10
8 #include "base/callback.h" 11 #include "base/callback.h"
9 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
10 13
14 namespace base {
15 class RefCountedMemory;
16 }
17
11 namespace zip { 18 namespace zip {
12 19
13 // Zip the contents of src_dir into dest_file. src_path must be a directory. 20 // Zip the contents of src_dir into dest_file. src_path must be a directory.
14 // An entry will *not* be created in the zip for the root folder -- children 21 // An entry will *not* be created in the zip for the root folder -- children
15 // of src_dir will be at the root level of the created zip. For each file in 22 // of src_dir will be at the root level of the created zip. For each file in
16 // src_dir, include it only if the callback |filter_cb| returns true. Otherwise 23 // src_dir, include it only if the callback |filter_cb| returns true. Otherwise
17 // omit it. 24 // omit it.
18 typedef base::Callback<bool(const base::FilePath&)> FilterCallback; 25 typedef base::Callback<bool(const base::FilePath&)> FilterCallback;
19 bool ZipWithFilterCallback(const base::FilePath& src_dir, 26 bool ZipWithFilterCallback(const base::FilePath& src_dir,
20 const base::FilePath& dest_file, 27 const base::FilePath& dest_file,
21 const FilterCallback& filter_cb); 28 const FilterCallback& filter_cb);
22 29
23 // Convenience method for callers who don't need to set up the filter callback. 30 // Convenience method for callers who don't need to set up the filter callback.
24 // If |include_hidden_files| is true, files starting with "." are included. 31 // If |include_hidden_files| is true, files starting with "." are included.
25 // Otherwise they are omitted. 32 // Otherwise they are omitted.
26 bool Zip(const base::FilePath& src_dir, const base::FilePath& dest_file, 33 bool Zip(const base::FilePath& src_dir, const base::FilePath& dest_file,
27 bool include_hidden_files); 34 bool include_hidden_files);
28 35
29 #if defined(OS_POSIX) 36 #if defined(OS_POSIX)
30 // Zips files listed in |src_relative_paths| to destination specified by file 37 // Zips files listed in |src_relative_paths| to destination specified by file
31 // descriptor |dest_fd|. The paths listed in |src_relative_paths| are relative 38 // descriptor |dest_fd|. The paths listed in |src_relative_paths| are relative
32 // to the |src_dir| and will be used as the file names in the created zip file. 39 // to the |src_dir| and will be used as the file names in the created zip file.
33 // All source paths must be under |src_dir| in the file system hierarchy. 40 // All source paths must be under |src_dir| in the file system hierarchy.
34 bool ZipFiles(const base::FilePath& src_dir, 41 bool ZipFiles(const base::FilePath& src_dir,
35 const std::vector<base::FilePath>& src_relative_paths, 42 const std::vector<base::FilePath>& src_relative_paths,
36 int dest_fd); 43 int dest_fd);
37 #endif // defined(OS_POSIX) 44 #endif // defined(OS_POSIX)
38 45
46 // Adds to |zip_file| files using contents from memory. |zip_file| is created if
47 // it does not exist. |files| contains a map with the file path to
48 // be stored in the zip file plus its contents. The FilePath in |files| may not
49 // be empty, absolute or contain a '..' component, else the function fails.
50 // The paths must therefore be relative and preferably canonicalized.
51 // Calling this with an empty |files| has no effect.
52 //
53 // If |append| is true, the new files are appended to an already existing file,
54 // if any. Else, the file is recreated from scratch, meaning, all previous
55 // contents are deleted without the possibility of recovery.
56 //
57 // If the RefCountedMemory in |files| is NULL, the file is removed from the zip
58 // archive. If the RefCountedMemory in |files| is not NULL, a file will be
59 // created with those contents. The contents can have a size of 0 bytes.
60 // Note: the data passed in |files| is copied. This function does not keep any
61 // references to the original data after it returns.
62 //
63 // If the FilePath ends with a path separator (a slash), a folder is created.
64 // Note: the contents for a folder must be either NULL or 0-byte big, so the
65 // folder will be removed or added, respectively.
66 typedef std::map<base::FilePath, scoped_refptr<base::RefCountedMemory> >
67 ZipContents;
68 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
69 const ZipContents& files,
70 bool append);
71
39 // Unzip the contents of zip_file into dest_dir. 72 // Unzip the contents of zip_file into dest_dir.
40 bool Unzip(const base::FilePath& zip_file, const base::FilePath& dest_dir); 73 bool Unzip(const base::FilePath& zip_file, const base::FilePath& dest_dir);
41 74
42 } // namespace zip 75 } // namespace zip
43 76
44 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_H_ 77 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698