summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreehugger Robot2017-03-23 12:59:46 -0500
committerGerrit Code Review2017-03-23 12:59:47 -0500
commit0e19795a621ddb9912edc58b832f078405e485fd (patch)
tree327d33a5dd15c87f9f297f5b241b1d585b104261 /include
parent27a091d4a1ae616f3a16ba68e1b8d09fd1d8370e (diff)
parent537713bace8975d02576225536ec55bd61f9ca91 (diff)
downloadplatform-system-core-0e19795a621ddb9912edc58b832f078405e485fd.tar.gz
platform-system-core-0e19795a621ddb9912edc58b832f078405e485fd.tar.xz
platform-system-core-0e19795a621ddb9912edc58b832f078405e485fd.zip
Merge "libziparchive: Add ability to backup in ZipWriter"
Diffstat (limited to 'include')
-rw-r--r--include/ziparchive/zip_writer.h56
1 files changed, 37 insertions, 19 deletions
diff --git a/include/ziparchive/zip_writer.h b/include/ziparchive/zip_writer.h
index 0b6ede45c..41ca2e1a3 100644
--- a/include/ziparchive/zip_writer.h
+++ b/include/ziparchive/zip_writer.h
@@ -17,15 +17,16 @@
17#ifndef LIBZIPARCHIVE_ZIPWRITER_H_ 17#ifndef LIBZIPARCHIVE_ZIPWRITER_H_
18#define LIBZIPARCHIVE_ZIPWRITER_H_ 18#define LIBZIPARCHIVE_ZIPWRITER_H_
19 19
20#include "android-base/macros.h"
21#include <utils/Compat.h>
22
23#include <cstdio> 20#include <cstdio>
24#include <ctime> 21#include <ctime>
22#include <zlib.h>
23
25#include <memory> 24#include <memory>
26#include <string> 25#include <string>
27#include <vector> 26#include <vector>
28#include <zlib.h> 27
28#include "android-base/macros.h"
29#include "utils/Compat.h"
29 30
30/** 31/**
31 * Writes a Zip file via a stateful interface. 32 * Writes a Zip file via a stateful interface.
@@ -63,6 +64,20 @@ public:
63 kAlign32 = 0x02, 64 kAlign32 = 0x02,
64 }; 65 };
65 66
67 /**
68 * A struct representing a zip file entry.
69 */
70 struct FileEntry {
71 std::string path;
72 uint16_t compression_method;
73 uint32_t crc32;
74 uint32_t compressed_size;
75 uint32_t uncompressed_size;
76 uint16_t last_mod_time;
77 uint16_t last_mod_date;
78 uint32_t local_file_header_offset;
79 };
80
66 static const char* ErrorCodeString(int32_t error_code); 81 static const char* ErrorCodeString(int32_t error_code);
67 82
68 /** 83 /**
@@ -122,6 +137,19 @@ public:
122 int32_t FinishEntry(); 137 int32_t FinishEntry();
123 138
124 /** 139 /**
140 * Discards the last-written entry. Can only be called after an entry has been written using
141 * FinishEntry().
142 * Returns 0 on success, and an error value < 0 on failure.
143 */
144 int32_t DiscardLastEntry();
145
146 /**
147 * Sets `out_entry` to the last entry written after a call to FinishEntry().
148 * Returns 0 on success, and an error value < 0 if no entries have been written.
149 */
150 int32_t GetLastEntry(FileEntry* out_entry);
151
152 /**
125 * Writes the Central Directory Headers and flushes the zip file stream. 153 * Writes the Central Directory Headers and flushes the zip file stream.
126 * Returns 0 on success, and an error value < 0 on failure. 154 * Returns 0 on success, and an error value < 0 on failure.
127 */ 155 */
@@ -130,22 +158,11 @@ public:
130private: 158private:
131 DISALLOW_COPY_AND_ASSIGN(ZipWriter); 159 DISALLOW_COPY_AND_ASSIGN(ZipWriter);
132 160
133 struct FileInfo {
134 std::string path;
135 uint16_t compression_method;
136 uint32_t crc32;
137 uint32_t compressed_size;
138 uint32_t uncompressed_size;
139 uint16_t last_mod_time;
140 uint16_t last_mod_date;
141 uint32_t local_file_header_offset;
142 };
143
144 int32_t HandleError(int32_t error_code); 161 int32_t HandleError(int32_t error_code);
145 int32_t PrepareDeflate(); 162 int32_t PrepareDeflate();
146 int32_t StoreBytes(FileInfo* file, const void* data, size_t len); 163 int32_t StoreBytes(FileEntry* file, const void* data, size_t len);
147 int32_t CompressBytes(FileInfo* file, const void* data, size_t len); 164 int32_t CompressBytes(FileEntry* file, const void* data, size_t len);
148 int32_t FlushCompressedBytes(FileInfo* file); 165 int32_t FlushCompressedBytes(FileEntry* file);
149 166
150 enum class State { 167 enum class State {
151 kWritingZip, 168 kWritingZip,
@@ -157,7 +174,8 @@ private:
157 FILE* file_; 174 FILE* file_;
158 off64_t current_offset_; 175 off64_t current_offset_;
159 State state_; 176 State state_;
160 std::vector<FileInfo> files_; 177 std::vector<FileEntry> files_;
178 FileEntry current_file_entry_;
161 179
162 std::unique_ptr<z_stream, void(*)(z_stream*)> z_stream_; 180 std::unique_ptr<z_stream, void(*)(z_stream*)> z_stream_;
163 std::vector<uint8_t> buffer_; 181 std::vector<uint8_t> buffer_;