summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ziparchive/zip_archive.h31
-rw-r--r--include/ziparchive/zip_writer.h11
2 files changed, 18 insertions, 24 deletions
diff --git a/include/ziparchive/zip_archive.h b/include/ziparchive/zip_archive.h
index ece86931a..73ae68d3f 100644
--- a/include/ziparchive/zip_archive.h
+++ b/include/ziparchive/zip_archive.h
@@ -28,8 +28,8 @@
28 28
29/* Zip compression methods we support */ 29/* Zip compression methods we support */
30enum { 30enum {
31 kCompressStored = 0, // no compression 31 kCompressStored = 0, // no compression
32 kCompressDeflated = 8, // standard deflate 32 kCompressDeflated = 8, // standard deflate
33}; 33};
34 34
35struct ZipString { 35struct ZipString {
@@ -44,19 +44,17 @@ struct ZipString {
44 explicit ZipString(const char* entry_name); 44 explicit ZipString(const char* entry_name);
45 45
46 bool operator==(const ZipString& rhs) const { 46 bool operator==(const ZipString& rhs) const {
47 return name && (name_length == rhs.name_length) && 47 return name && (name_length == rhs.name_length) && (memcmp(name, rhs.name, name_length) == 0);
48 (memcmp(name, rhs.name, name_length) == 0);
49 } 48 }
50 49
51 bool StartsWith(const ZipString& prefix) const { 50 bool StartsWith(const ZipString& prefix) const {
52 return name && (name_length >= prefix.name_length) && 51 return name && (name_length >= prefix.name_length) &&
53 (memcmp(name, prefix.name, prefix.name_length) == 0); 52 (memcmp(name, prefix.name, prefix.name_length) == 0);
54 } 53 }
55 54
56 bool EndsWith(const ZipString& suffix) const { 55 bool EndsWith(const ZipString& suffix) const {
57 return name && (name_length >= suffix.name_length) && 56 return name && (name_length >= suffix.name_length) &&
58 (memcmp(name + name_length - suffix.name_length, suffix.name, 57 (memcmp(name + name_length - suffix.name_length, suffix.name, suffix.name_length) == 0);
59 suffix.name_length) == 0);
60 } 58 }
61}; 59};
62 60
@@ -134,11 +132,11 @@ int32_t OpenArchive(const char* fileName, ZipArchiveHandle* handle);
134 * 132 *
135 * Returns 0 on success, and negative values on failure. 133 * Returns 0 on success, and negative values on failure.
136 */ 134 */
137int32_t OpenArchiveFd(const int fd, const char* debugFileName, 135int32_t OpenArchiveFd(const int fd, const char* debugFileName, ZipArchiveHandle* handle,
138 ZipArchiveHandle *handle, bool assume_ownership = true); 136 bool assume_ownership = true);
139 137
140int32_t OpenArchiveFromMemory(void* address, size_t length, const char* debugFileName, 138int32_t OpenArchiveFromMemory(void* address, size_t length, const char* debugFileName,
141 ZipArchiveHandle *handle); 139 ZipArchiveHandle* handle);
142/* 140/*
143 * Close archive, releasing resources associated with it. This will 141 * Close archive, releasing resources associated with it. This will
144 * unmap the central directory of the zipfile and free all internal 142 * unmap the central directory of the zipfile and free all internal
@@ -164,8 +162,7 @@ void CloseArchive(ZipArchiveHandle handle);
164 * On non-Windows platforms this method does not modify internal state and 162 * On non-Windows platforms this method does not modify internal state and
165 * can be called concurrently. 163 * can be called concurrently.
166 */ 164 */
167int32_t FindEntry(const ZipArchiveHandle handle, const ZipString& entryName, 165int32_t FindEntry(const ZipArchiveHandle handle, const ZipString& entryName, ZipEntry* data);
168 ZipEntry* data);
169 166
170/* 167/*
171 * Start iterating over all entries of a zip file. The order of iteration 168 * Start iterating over all entries of a zip file. The order of iteration
@@ -180,8 +177,7 @@ int32_t FindEntry(const ZipArchiveHandle handle, const ZipString& entryName,
180 * 177 *
181 * Returns 0 on success and negative values on failure. 178 * Returns 0 on success and negative values on failure.
182 */ 179 */
183int32_t StartIteration(ZipArchiveHandle handle, void** cookie_ptr, 180int32_t StartIteration(ZipArchiveHandle handle, void** cookie_ptr, const ZipString* optional_prefix,
184 const ZipString* optional_prefix,
185 const ZipString* optional_suffix); 181 const ZipString* optional_suffix);
186 182
187/* 183/*
@@ -217,8 +213,7 @@ int32_t ExtractEntryToFile(ZipArchiveHandle handle, ZipEntry* entry, int fd);
217 * 213 *
218 * Returns 0 on success and negative values on failure. 214 * Returns 0 on success and negative values on failure.
219 */ 215 */
220int32_t ExtractToMemory(ZipArchiveHandle handle, ZipEntry* entry, 216int32_t ExtractToMemory(ZipArchiveHandle handle, ZipEntry* entry, uint8_t* begin, uint32_t size);
221 uint8_t* begin, uint32_t size);
222 217
223int GetFileDescriptor(const ZipArchiveHandle handle); 218int GetFileDescriptor(const ZipArchiveHandle handle);
224 219
@@ -230,9 +225,9 @@ typedef bool (*ProcessZipEntryFunction)(const uint8_t* buf, size_t buf_size, voi
230/* 225/*
231 * Stream the uncompressed data through the supplied function, 226 * Stream the uncompressed data through the supplied function,
232 * passing cookie to it each time it gets called. 227 * passing cookie to it each time it gets called.
233*/ 228 */
234int32_t ProcessZipEntryContents(ZipArchiveHandle handle, ZipEntry* entry, 229int32_t ProcessZipEntryContents(ZipArchiveHandle handle, ZipEntry* entry,
235 ProcessZipEntryFunction func, void* cookie); 230 ProcessZipEntryFunction func, void* cookie);
236#endif 231#endif
237 232
238#endif // LIBZIPARCHIVE_ZIPARCHIVE_H_ 233#endif // LIBZIPARCHIVE_ZIPARCHIVE_H_
diff --git a/include/ziparchive/zip_writer.h b/include/ziparchive/zip_writer.h
index 08ead4845..94595143d 100644
--- a/include/ziparchive/zip_writer.h
+++ b/include/ziparchive/zip_writer.h
@@ -17,9 +17,9 @@
17#ifndef LIBZIPARCHIVE_ZIPWRITER_H_ 17#ifndef LIBZIPARCHIVE_ZIPWRITER_H_
18#define LIBZIPARCHIVE_ZIPWRITER_H_ 18#define LIBZIPARCHIVE_ZIPWRITER_H_
19 19
20#include <zlib.h>
20#include <cstdio> 21#include <cstdio>
21#include <ctime> 22#include <ctime>
22#include <zlib.h>
23 23
24#include <memory> 24#include <memory>
25#include <string> 25#include <string>
@@ -50,7 +50,7 @@
50 * fclose(file); 50 * fclose(file);
51 */ 51 */
52class ZipWriter { 52class ZipWriter {
53public: 53 public:
54 enum { 54 enum {
55 /** 55 /**
56 * Flag to compress the zip entry using deflate. 56 * Flag to compress the zip entry using deflate.
@@ -120,8 +120,7 @@ public:
120 /** 120 /**
121 * Same as StartAlignedEntry(const char*, size_t), but sets a last modified time for the entry. 121 * Same as StartAlignedEntry(const char*, size_t), but sets a last modified time for the entry.
122 */ 122 */
123 int32_t StartAlignedEntryWithTime(const char* path, size_t flags, time_t time, 123 int32_t StartAlignedEntryWithTime(const char* path, size_t flags, time_t time, uint32_t alignment);
124 uint32_t alignment);
125 124
126 /** 125 /**
127 * Writes bytes to the zip file for the previously started zip entry. 126 * Writes bytes to the zip file for the previously started zip entry.
@@ -156,7 +155,7 @@ public:
156 */ 155 */
157 int32_t Finish(); 156 int32_t Finish();
158 157
159private: 158 private:
160 DISALLOW_COPY_AND_ASSIGN(ZipWriter); 159 DISALLOW_COPY_AND_ASSIGN(ZipWriter);
161 160
162 int32_t HandleError(int32_t error_code); 161 int32_t HandleError(int32_t error_code);
@@ -179,7 +178,7 @@ private:
179 std::vector<FileEntry> files_; 178 std::vector<FileEntry> files_;
180 FileEntry current_file_entry_; 179 FileEntry current_file_entry_;
181 180
182 std::unique_ptr<z_stream, void(*)(z_stream*)> z_stream_; 181 std::unique_ptr<z_stream, void (*)(z_stream*)> z_stream_;
183 std::vector<uint8_t> buffer_; 182 std::vector<uint8_t> buffer_;
184}; 183};
185 184