-
Notifications
You must be signed in to change notification settings - Fork 16
/
jszip.javascript.txt
273 lines (212 loc) · 14.6 KB
/
jszip.javascript.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
JSZIP
ALTERNATIVES ==> # - jszip (preferred):
# - browser/Node
# - streaming, zip64, stats, comments, metadata, crc32
# - node-zip-stream
# - Node only
# - streaming, zip64, stats, comments
# - node-archiver: abstraction layer on top of it
# - node-stream-zip:
# - Node only
# - unzip only
# - streaming, zip64
# - yauzl|yazl:
# - not well maintained
# - Node only
# - streaming, stats, zip64, comments, metadata
# - adm-zip: not well maintained
# - zip.js: not maintained
# - node-zip: not maintained
# - node-unzip: not maintained
# - node-zipstream: not maintained
# - node-native-zip: not maintained
VERSION ==> #3.10.1
FEATURES ==> # - streaming
# - browser/Node
# - ZIP64 (limited support)
# - comments
# - Unix|Windows permissions
# - mtime
# - filename encoding (beyond UTF-8)
# - CRC32 checksum
# - "data descriptors"
# - compression (deflate)
# - progress callback
NOT SUPPORTED ==> # - password-protected archives
# - multi-volume archives
/=+===============================+=\
/ : : \
)==: WRITE ARCHIVE :==(
\ :_______________________________: /
\=+===============================+=/
new Jszip() #Zip archive
JSZIP.generateAsync(GOPTS) #Serialize zip archive
->PROMISE_VAL #GOPTS:
# - type 'OUTPUT_TYPE': VAL type
# - mimeType 'MIME' (def: 'application/zip'): when OUTPUT_TYPE is 'blob'
JSZIP.generateNodeStream
(GOPTS, PROGRESS_FUNC)->STREAM #Same with OUTPUT_TYPE Node STREAM
JSZIP.generateInternalStream
(GOPTS)->STREAMHELPER #Same with OUTPUT_TYPE STREAMHELPER
/=+===============================+=\
/ : : \
)==: READ ARCHIVE :==(
\ :_______________________________: /
\=+===============================+=/
JSZIP.loadAsync(VAL[, LOPTS]) #Parse zip archive. Its files are added to JSZIP.
->PROMISE_JSZIP #VAL is archive with type INPUT_TYPE
loadAsync(...) #Same as (new Jszip()).loadAsync(...)
/=+===============================+=\
/ : : \
)==: WRITE FILE :==(
\ :_______________________________: /
\=+===============================+=/
JSZIP.file
('PATH', CONTENT[, FOPTS]) #Add a file to the archive
->JSZIP #CONTENT type can be any INPUT_TYPE
JSZIP.remove('PATH')->JSZIP #Remove a file from archive
/=+===============================+=\
/ : : \
)==: READ FILE :==(
\ :_______________________________: /
\=+===============================+=/
JSZIP.files #{ 'PATH': FILE, ... }
FILE.name #'PATH'
FILE.unsafeOriginalName #Original 'PATH' when it was renamed due to security reasons
FILE.options #FOPTS
FILE.async
('OUTPUT_TYPE'[, PROGRESS_FUNC])
->PROMISE_VAL #Retrieve FILE CONTENT.
FILE.nodeStream
('nodebuffer'[, PROGRESS_FUNC])
->STREAM #Same with Node STREAM
FILE.internalStream('OUTPUT_TYPE')
->STREAMHELPER #Same with STREAMHELPER
JSZIP.file('PATH')->FILE|null #
JSZIP.file(REGEXP)->FILE_ARR #
JSZIP.forEach(FUNC('PATH', FILE)) #
JSZIP.filter
(FUNC('PATH', FILE)->BOOL)
->JSZIP2 #
/=+===============================+=\
/ : : \
)==: FOLDERS :==(
\ :_______________________________: /
\=+===============================+=/
JSZIP.folder('PATH')->JSZIP2 #JSZIP2 is like JSZIP except:
# - 'PATH' is prepended to files' 'PATH'
# - only includes files inside that 'PATH'
#Create directory entry if does not exist.
JSZIP.folder(REGEXP)->FILE_ARR #Like JSZIP.file() but only matches directories
FILE|FOPTS.dir #BOOL (def: false). Entry is a directory.
#CONTENT can be null
LOPTS|FOPTS.createFolders #BOOL (def: true). Create entries for each parent folder in 'PATH'
/=+===============================+=\
/ : : \
)==: TYPES :==(
\ :_______________________________: /
\=+===============================+=/
INPUT_TYPE #Input|parse type of:
# - zip archive (loadAsync())
# - FILE (file())
#Can be:
# - STR
# - BUFFER (Node only)
# - ARRBUFFER|UINT8_ARR
# - BLOB (browser only)
# - STREAM (Node only) (not with loadAsync())
OUTPUT_TYPE #Output|serialization type of:
# - zip archive (generateAsync|generateNodeStream|generateInternalStream())
# - FILE (FILE.async|nodeStream|internalStream())
#Can be:
# - 'base64': base64 STR
# - 'string': UTF8 STR
# - 'binarystring': binary STR
# - 'array': NUM_ARR
# - 'nodebuffer': BUFFER (Node only)
# - 'arraybuffer': ARRBUFFER
# - 'uint8array': UINT8ARR
# - 'blob': BLOB (browser only)
JSZIP.support.
nodebuffer|arraybuffer|
uint8array|blob|nodestream #BOOL. Platform support
LOPTS|FOPTS.base64 #BOOL (def: false). When input archive|FILE is base64 STR
FOPTS.binary #BOOL. Whether input FILE is text (i.e. UTF8 encoding) or binary.
#Def: false if STR and FOPTS.base64 false, true otherwise
STREAMHELPER #Similar to Node STREAM but works on browsers too
#Must specify the 'data' VAL OUTPUT_TYPE. Cannot be 'base64'|'array'|'blob'
#Some browsers need this because they crash if archive is too big and is not streamed.
STREAMHELPER.on
('data', FUNC(VAL, METADATA))
->STREAMHELPER #
STREAMHELPER.on('end', FUNC())
->STREAMHELPER #
STREAMHELPER.on
('error', FUNC(ERROR))
->STREAMHELPER #
STREAMHELPER.resume|pause()
->STREAMHELPER #It is paused initially
STREAMHELPER.accumulate
([PROGRESS_FUNC])->PROMISE_VAL #Read whole stream at once
/=+===============================+=\
/ : : \
)==: METADATA :==(
\ :_______________________________: /
\=+===============================+=/
JSZIP|FILE|GOPTS|FOPTS.comment #STR. Any metadata
FILE|FOPTS.unixPermissions #'OCTAL' (def: none)
#Can include special permissions and file types, like FS.mode (e.g. '664' or '0100664')
FILE|FOPTS.dosPermissions #'OCTAL' (def: none):
# - 0: read-only
# - 1: hidden
# - 2: system
# - 4: volume label
# - 10: directory
# - 11: archive
GOPTS.platform #'UNIX|DOS' or any process.platform value (def: 'DOS')
#Whether to use dosPermissions|unixPermissions
FILE|FOPTS.date #DATE (def: now). FILE mtime
/=+===============================+=\
/ : : \
)==: ENCODING :==(
\ :_______________________________: /
\=+===============================+=/
GOPTS.encodeFileName(STR) #Charset encoding for filenames (def: UTF8 encoding)
->UINT8ARR #Def: UTF8 encoding
#Changing it means reader is expected to know how to decode, i.e. create issues if not.
LOPTS.decodeFileName(UINT8ARR)
->STR #Inverse. Def: UTF8 decoding.
/=+===============================+=\
/ : : \
)==: CHECKSUM :==(
\ :_______________________________: /
\=+===============================+=/
LOPTS.checkCRC32 BOOL #Throw if wrong checksum (def: false)
GOPTS.streamFiles BOOL #Use "data descriptors" in output:
# - put size and CRC32 checksum at end of archive instead of beginning
# - i.e. data can be streamed, requiring less memory
# - however some applications might not understand "data descriptors", i.e. fail to read the archive
#Def: false
#Note: "data descriptors" can always be read in input
/=+===============================+=\
/ : : \
)==: COMPRESSION :==(
\ :_______________________________: /
\=+===============================+=/
GOPTS|FOPTS.compression #STR among 'STORE' (def, no compression) and 'DEFLATE'
GOPTS|FOPTS.compressionOptions #OBJ (with 'DEFLATE' only):
# - level 1-9
LOPTS|FOPTS.optimizedBinaryString #BOOL (def: false). Input FILE|archive has already been "prepared with a 0xff mask"
#Useless performance optimization
/=+===============================+=\
/ : : \
)==: PROGRESS :==(
\ :_______________________________: /
\=+===============================+=/
GOPTS.onUpdate PROGRESS_FUNC #
PROGRESS_FUNC #Progress callback FUNC(METADATA)
METADATA #
METADATA.currentFile #'PATH'
METADATA.percent #0-100