node-red-contrib-tak-registration 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +35 -0
  3. package/node_modules/adm-zip/LICENSE +21 -0
  4. package/node_modules/adm-zip/README.md +65 -0
  5. package/node_modules/adm-zip/adm-zip.js +783 -0
  6. package/node_modules/adm-zip/headers/entryHeader.js +338 -0
  7. package/node_modules/adm-zip/headers/index.js +2 -0
  8. package/node_modules/adm-zip/headers/mainHeader.js +129 -0
  9. package/node_modules/adm-zip/methods/deflater.js +33 -0
  10. package/node_modules/adm-zip/methods/index.js +3 -0
  11. package/node_modules/adm-zip/methods/inflater.js +31 -0
  12. package/node_modules/adm-zip/methods/zipcrypto.js +170 -0
  13. package/node_modules/adm-zip/package.json +77 -0
  14. package/node_modules/adm-zip/util/constants.js +142 -0
  15. package/node_modules/adm-zip/util/errors.js +35 -0
  16. package/node_modules/adm-zip/util/fattr.js +79 -0
  17. package/node_modules/adm-zip/util/fileSystem.js +11 -0
  18. package/node_modules/adm-zip/util/index.js +4 -0
  19. package/node_modules/adm-zip/util/utils.js +246 -0
  20. package/node_modules/adm-zip/zipEntry.js +333 -0
  21. package/node_modules/adm-zip/zipFile.js +384 -0
  22. package/node_modules/asynckit/LICENSE +21 -0
  23. package/node_modules/asynckit/README.md +233 -0
  24. package/node_modules/asynckit/bench.js +76 -0
  25. package/node_modules/asynckit/index.js +6 -0
  26. package/node_modules/asynckit/lib/abort.js +29 -0
  27. package/node_modules/asynckit/lib/async.js +34 -0
  28. package/node_modules/asynckit/lib/defer.js +26 -0
  29. package/node_modules/asynckit/lib/iterate.js +75 -0
  30. package/node_modules/asynckit/lib/readable_asynckit.js +91 -0
  31. package/node_modules/asynckit/lib/readable_parallel.js +25 -0
  32. package/node_modules/asynckit/lib/readable_serial.js +25 -0
  33. package/node_modules/asynckit/lib/readable_serial_ordered.js +29 -0
  34. package/node_modules/asynckit/lib/state.js +37 -0
  35. package/node_modules/asynckit/lib/streamify.js +141 -0
  36. package/node_modules/asynckit/lib/terminator.js +29 -0
  37. package/node_modules/asynckit/package.json +91 -0
  38. package/node_modules/asynckit/parallel.js +43 -0
  39. package/node_modules/asynckit/serial.js +17 -0
  40. package/node_modules/asynckit/serialOrdered.js +75 -0
  41. package/node_modules/asynckit/stream.js +21 -0
  42. package/node_modules/axios/CHANGELOG.md +836 -0
  43. package/node_modules/axios/LICENSE +19 -0
  44. package/node_modules/axios/README.md +892 -0
  45. package/node_modules/axios/SECURITY.md +5 -0
  46. package/node_modules/axios/UPGRADE_GUIDE.md +162 -0
  47. package/node_modules/axios/dist/axios.js +2275 -0
  48. package/node_modules/axios/dist/axios.map +1 -0
  49. package/node_modules/axios/dist/axios.min.js +2 -0
  50. package/node_modules/axios/dist/axios.min.map +1 -0
  51. package/node_modules/axios/index.d.ts +206 -0
  52. package/node_modules/axios/index.js +1 -0
  53. package/node_modules/axios/lib/adapters/README.md +37 -0
  54. package/node_modules/axios/lib/adapters/http.js +363 -0
  55. package/node_modules/axios/lib/adapters/xhr.js +212 -0
  56. package/node_modules/axios/lib/axios.js +57 -0
  57. package/node_modules/axios/lib/cancel/Cancel.js +19 -0
  58. package/node_modules/axios/lib/cancel/CancelToken.js +119 -0
  59. package/node_modules/axios/lib/cancel/isCancel.js +5 -0
  60. package/node_modules/axios/lib/core/Axios.js +148 -0
  61. package/node_modules/axios/lib/core/InterceptorManager.js +54 -0
  62. package/node_modules/axios/lib/core/README.md +8 -0
  63. package/node_modules/axios/lib/core/buildFullPath.js +20 -0
  64. package/node_modules/axios/lib/core/createError.js +18 -0
  65. package/node_modules/axios/lib/core/dispatchRequest.js +87 -0
  66. package/node_modules/axios/lib/core/enhanceError.js +43 -0
  67. package/node_modules/axios/lib/core/mergeConfig.js +99 -0
  68. package/node_modules/axios/lib/core/settle.js +25 -0
  69. package/node_modules/axios/lib/core/transformData.js +22 -0
  70. package/node_modules/axios/lib/defaults.js +134 -0
  71. package/node_modules/axios/lib/env/README.md +3 -0
  72. package/node_modules/axios/lib/env/data.js +3 -0
  73. package/node_modules/axios/lib/helpers/README.md +7 -0
  74. package/node_modules/axios/lib/helpers/bind.js +11 -0
  75. package/node_modules/axios/lib/helpers/buildURL.js +70 -0
  76. package/node_modules/axios/lib/helpers/combineURLs.js +14 -0
  77. package/node_modules/axios/lib/helpers/cookies.js +53 -0
  78. package/node_modules/axios/lib/helpers/deprecatedMethod.js +24 -0
  79. package/node_modules/axios/lib/helpers/isAbsoluteURL.js +14 -0
  80. package/node_modules/axios/lib/helpers/isAxiosError.js +11 -0
  81. package/node_modules/axios/lib/helpers/isURLSameOrigin.js +68 -0
  82. package/node_modules/axios/lib/helpers/normalizeHeaderName.js +12 -0
  83. package/node_modules/axios/lib/helpers/parseHeaders.js +53 -0
  84. package/node_modules/axios/lib/helpers/spread.js +27 -0
  85. package/node_modules/axios/lib/helpers/validator.js +82 -0
  86. package/node_modules/axios/lib/utils.js +349 -0
  87. package/node_modules/axios/package.json +113 -0
  88. package/node_modules/axios/tsconfig.json +14 -0
  89. package/node_modules/axios/tslint.json +6 -0
  90. package/node_modules/combined-stream/License +19 -0
  91. package/node_modules/combined-stream/Readme.md +138 -0
  92. package/node_modules/combined-stream/lib/combined_stream.js +208 -0
  93. package/node_modules/combined-stream/package.json +57 -0
  94. package/node_modules/combined-stream/yarn.lock +17 -0
  95. package/node_modules/delayed-stream/.npmignore +1 -0
  96. package/node_modules/delayed-stream/License +19 -0
  97. package/node_modules/delayed-stream/Makefile +7 -0
  98. package/node_modules/delayed-stream/Readme.md +141 -0
  99. package/node_modules/delayed-stream/lib/delayed_stream.js +107 -0
  100. package/node_modules/delayed-stream/package.json +62 -0
  101. package/node_modules/follow-redirects/LICENSE +18 -0
  102. package/node_modules/follow-redirects/README.md +148 -0
  103. package/node_modules/follow-redirects/debug.js +15 -0
  104. package/node_modules/follow-redirects/http.js +1 -0
  105. package/node_modules/follow-redirects/https.js +1 -0
  106. package/node_modules/follow-redirects/index.js +569 -0
  107. package/node_modules/follow-redirects/package.json +95 -0
  108. package/node_modules/form-data/License +19 -0
  109. package/node_modules/form-data/README.md.bak +358 -0
  110. package/node_modules/form-data/Readme.md +358 -0
  111. package/node_modules/form-data/index.d.ts +62 -0
  112. package/node_modules/form-data/lib/browser.js +2 -0
  113. package/node_modules/form-data/lib/form_data.js +501 -0
  114. package/node_modules/form-data/lib/populate.js +10 -0
  115. package/node_modules/form-data/package.json +101 -0
  116. package/node_modules/mime-db/HISTORY.md +499 -0
  117. package/node_modules/mime-db/LICENSE +22 -0
  118. package/node_modules/mime-db/README.md +100 -0
  119. package/node_modules/mime-db/db.json +8471 -0
  120. package/node_modules/mime-db/index.js +11 -0
  121. package/node_modules/mime-db/package.json +102 -0
  122. package/node_modules/mime-types/HISTORY.md +388 -0
  123. package/node_modules/mime-types/LICENSE +23 -0
  124. package/node_modules/mime-types/README.md +113 -0
  125. package/node_modules/mime-types/index.js +188 -0
  126. package/node_modules/mime-types/package.json +87 -0
  127. package/node_modules/uuid/CHANGELOG.md +229 -0
  128. package/node_modules/uuid/CONTRIBUTING.md +18 -0
  129. package/node_modules/uuid/LICENSE.md +9 -0
  130. package/node_modules/uuid/README.md +505 -0
  131. package/node_modules/uuid/dist/bin/uuid +2 -0
  132. package/node_modules/uuid/dist/esm-browser/index.js +9 -0
  133. package/node_modules/uuid/dist/esm-browser/md5.js +215 -0
  134. package/node_modules/uuid/dist/esm-browser/nil.js +1 -0
  135. package/node_modules/uuid/dist/esm-browser/parse.js +35 -0
  136. package/node_modules/uuid/dist/esm-browser/regex.js +1 -0
  137. package/node_modules/uuid/dist/esm-browser/rng.js +19 -0
  138. package/node_modules/uuid/dist/esm-browser/sha1.js +96 -0
  139. package/node_modules/uuid/dist/esm-browser/stringify.js +30 -0
  140. package/node_modules/uuid/dist/esm-browser/v1.js +95 -0
  141. package/node_modules/uuid/dist/esm-browser/v3.js +4 -0
  142. package/node_modules/uuid/dist/esm-browser/v35.js +64 -0
  143. package/node_modules/uuid/dist/esm-browser/v4.js +24 -0
  144. package/node_modules/uuid/dist/esm-browser/v5.js +4 -0
  145. package/node_modules/uuid/dist/esm-browser/validate.js +7 -0
  146. package/node_modules/uuid/dist/esm-browser/version.js +11 -0
  147. package/node_modules/uuid/dist/esm-node/index.js +9 -0
  148. package/node_modules/uuid/dist/esm-node/md5.js +13 -0
  149. package/node_modules/uuid/dist/esm-node/nil.js +1 -0
  150. package/node_modules/uuid/dist/esm-node/parse.js +35 -0
  151. package/node_modules/uuid/dist/esm-node/regex.js +1 -0
  152. package/node_modules/uuid/dist/esm-node/rng.js +12 -0
  153. package/node_modules/uuid/dist/esm-node/sha1.js +13 -0
  154. package/node_modules/uuid/dist/esm-node/stringify.js +29 -0
  155. package/node_modules/uuid/dist/esm-node/v1.js +95 -0
  156. package/node_modules/uuid/dist/esm-node/v3.js +4 -0
  157. package/node_modules/uuid/dist/esm-node/v35.js +64 -0
  158. package/node_modules/uuid/dist/esm-node/v4.js +24 -0
  159. package/node_modules/uuid/dist/esm-node/v5.js +4 -0
  160. package/node_modules/uuid/dist/esm-node/validate.js +7 -0
  161. package/node_modules/uuid/dist/esm-node/version.js +11 -0
  162. package/node_modules/uuid/dist/index.js +79 -0
  163. package/node_modules/uuid/dist/md5-browser.js +223 -0
  164. package/node_modules/uuid/dist/md5.js +23 -0
  165. package/node_modules/uuid/dist/nil.js +8 -0
  166. package/node_modules/uuid/dist/parse.js +45 -0
  167. package/node_modules/uuid/dist/regex.js +8 -0
  168. package/node_modules/uuid/dist/rng-browser.js +26 -0
  169. package/node_modules/uuid/dist/rng.js +24 -0
  170. package/node_modules/uuid/dist/sha1-browser.js +104 -0
  171. package/node_modules/uuid/dist/sha1.js +23 -0
  172. package/node_modules/uuid/dist/stringify.js +39 -0
  173. package/node_modules/uuid/dist/umd/uuid.min.js +1 -0
  174. package/node_modules/uuid/dist/umd/uuidNIL.min.js +1 -0
  175. package/node_modules/uuid/dist/umd/uuidParse.min.js +1 -0
  176. package/node_modules/uuid/dist/umd/uuidStringify.min.js +1 -0
  177. package/node_modules/uuid/dist/umd/uuidValidate.min.js +1 -0
  178. package/node_modules/uuid/dist/umd/uuidVersion.min.js +1 -0
  179. package/node_modules/uuid/dist/umd/uuidv1.min.js +1 -0
  180. package/node_modules/uuid/dist/umd/uuidv3.min.js +1 -0
  181. package/node_modules/uuid/dist/umd/uuidv4.min.js +1 -0
  182. package/node_modules/uuid/dist/umd/uuidv5.min.js +1 -0
  183. package/node_modules/uuid/dist/uuid-bin.js +85 -0
  184. package/node_modules/uuid/dist/v1.js +107 -0
  185. package/node_modules/uuid/dist/v3.js +16 -0
  186. package/node_modules/uuid/dist/v35.js +78 -0
  187. package/node_modules/uuid/dist/v4.js +37 -0
  188. package/node_modules/uuid/dist/v5.js +16 -0
  189. package/node_modules/uuid/dist/validate.js +17 -0
  190. package/node_modules/uuid/dist/version.js +21 -0
  191. package/node_modules/uuid/package.json +164 -0
  192. package/node_modules/uuid/wrapper.mjs +10 -0
  193. package/package.json +32 -0
  194. package/tak-registration.html +111 -0
  195. package/tak-registration.js +169 -0
@@ -0,0 +1,783 @@
1
+ const Utils = require("./util");
2
+ const pth = require("path");
3
+ const ZipEntry = require("./zipEntry");
4
+ const ZipFile = require("./zipFile");
5
+
6
+ const get_Bool = (val, def) => (typeof val === "boolean" ? val : def);
7
+ const get_Str = (val, def) => (typeof val === "string" ? val : def);
8
+
9
+ const defaultOptions = {
10
+ // option "noSort" : if true it disables files sorting
11
+ noSort: false,
12
+ // read entries during load (initial loading may be slower)
13
+ readEntries: false,
14
+ // default method is none
15
+ method: Utils.Constants.NONE,
16
+ // file system
17
+ fs: null
18
+ };
19
+
20
+ module.exports = function (/**String*/ input, /** object */ options) {
21
+ let inBuffer = null;
22
+
23
+ // create object based default options, allowing them to be overwritten
24
+ const opts = Object.assign(Object.create(null), defaultOptions);
25
+
26
+ // test input variable
27
+ if (input && "object" === typeof input) {
28
+ // if value is not buffer we accept it to be object with options
29
+ if (!(input instanceof Uint8Array)) {
30
+ Object.assign(opts, input);
31
+ input = opts.input ? opts.input : undefined;
32
+ if (opts.input) delete opts.input;
33
+ }
34
+
35
+ // if input is buffer
36
+ if (Buffer.isBuffer(input)) {
37
+ inBuffer = input;
38
+ opts.method = Utils.Constants.BUFFER;
39
+ input = undefined;
40
+ }
41
+ }
42
+
43
+ // assign options
44
+ Object.assign(opts, options);
45
+
46
+ // instanciate utils filesystem
47
+ const filetools = new Utils(opts);
48
+
49
+ // if input is file name we retrieve its content
50
+ if (input && "string" === typeof input) {
51
+ // load zip file
52
+ if (filetools.fs.existsSync(input)) {
53
+ opts.method = Utils.Constants.FILE;
54
+ opts.filename = input;
55
+ inBuffer = filetools.fs.readFileSync(input);
56
+ } else {
57
+ throw new Error(Utils.Errors.INVALID_FILENAME);
58
+ }
59
+ }
60
+
61
+ // create variable
62
+ const _zip = new ZipFile(inBuffer, opts);
63
+
64
+ const { canonical, sanitize } = Utils;
65
+
66
+ function getEntry(/**Object*/ entry) {
67
+ if (entry && _zip) {
68
+ var item;
69
+ // If entry was given as a file name
70
+ if (typeof entry === "string") item = _zip.getEntry(entry);
71
+ // if entry was given as a ZipEntry object
72
+ if (typeof entry === "object" && typeof entry.entryName !== "undefined" && typeof entry.header !== "undefined") item = _zip.getEntry(entry.entryName);
73
+
74
+ if (item) {
75
+ return item;
76
+ }
77
+ }
78
+ return null;
79
+ }
80
+
81
+ function fixPath(zipPath) {
82
+ const { join, normalize, sep } = pth.posix;
83
+ // convert windows file separators and normalize
84
+ return join(".", normalize(sep + zipPath.split("\\").join(sep) + sep));
85
+ }
86
+
87
+ return {
88
+ /**
89
+ * Extracts the given entry from the archive and returns the content as a Buffer object
90
+ * @param entry ZipEntry object or String with the full path of the entry
91
+ *
92
+ * @return Buffer or Null in case of error
93
+ */
94
+ readFile: function (/**Object*/ entry, /*String, Buffer*/ pass) {
95
+ var item = getEntry(entry);
96
+ return (item && item.getData(pass)) || null;
97
+ },
98
+
99
+ /**
100
+ * Asynchronous readFile
101
+ * @param entry ZipEntry object or String with the full path of the entry
102
+ * @param callback
103
+ *
104
+ * @return Buffer or Null in case of error
105
+ */
106
+ readFileAsync: function (/**Object*/ entry, /**Function*/ callback) {
107
+ var item = getEntry(entry);
108
+ if (item) {
109
+ item.getDataAsync(callback);
110
+ } else {
111
+ callback(null, "getEntry failed for:" + entry);
112
+ }
113
+ },
114
+
115
+ /**
116
+ * Extracts the given entry from the archive and returns the content as plain text in the given encoding
117
+ * @param entry ZipEntry object or String with the full path of the entry
118
+ * @param encoding Optional. If no encoding is specified utf8 is used
119
+ *
120
+ * @return String
121
+ */
122
+ readAsText: function (/**Object*/ entry, /**String=*/ encoding) {
123
+ var item = getEntry(entry);
124
+ if (item) {
125
+ var data = item.getData();
126
+ if (data && data.length) {
127
+ return data.toString(encoding || "utf8");
128
+ }
129
+ }
130
+ return "";
131
+ },
132
+
133
+ /**
134
+ * Asynchronous readAsText
135
+ * @param entry ZipEntry object or String with the full path of the entry
136
+ * @param callback
137
+ * @param encoding Optional. If no encoding is specified utf8 is used
138
+ *
139
+ * @return String
140
+ */
141
+ readAsTextAsync: function (/**Object*/ entry, /**Function*/ callback, /**String=*/ encoding) {
142
+ var item = getEntry(entry);
143
+ if (item) {
144
+ item.getDataAsync(function (data, err) {
145
+ if (err) {
146
+ callback(data, err);
147
+ return;
148
+ }
149
+
150
+ if (data && data.length) {
151
+ callback(data.toString(encoding || "utf8"));
152
+ } else {
153
+ callback("");
154
+ }
155
+ });
156
+ } else {
157
+ callback("");
158
+ }
159
+ },
160
+
161
+ /**
162
+ * Remove the entry from the file or the entry and all it's nested directories and files if the given entry is a directory
163
+ *
164
+ * @param entry
165
+ */
166
+ deleteFile: function (/**Object*/ entry) {
167
+ // @TODO: test deleteFile
168
+ var item = getEntry(entry);
169
+ if (item) {
170
+ _zip.deleteEntry(item.entryName);
171
+ }
172
+ },
173
+
174
+ /**
175
+ * Adds a comment to the zip. The zip must be rewritten after adding the comment.
176
+ *
177
+ * @param comment
178
+ */
179
+ addZipComment: function (/**String*/ comment) {
180
+ // @TODO: test addZipComment
181
+ _zip.comment = comment;
182
+ },
183
+
184
+ /**
185
+ * Returns the zip comment
186
+ *
187
+ * @return String
188
+ */
189
+ getZipComment: function () {
190
+ return _zip.comment || "";
191
+ },
192
+
193
+ /**
194
+ * Adds a comment to a specified zipEntry. The zip must be rewritten after adding the comment
195
+ * The comment cannot exceed 65535 characters in length
196
+ *
197
+ * @param entry
198
+ * @param comment
199
+ */
200
+ addZipEntryComment: function (/**Object*/ entry, /**String*/ comment) {
201
+ var item = getEntry(entry);
202
+ if (item) {
203
+ item.comment = comment;
204
+ }
205
+ },
206
+
207
+ /**
208
+ * Returns the comment of the specified entry
209
+ *
210
+ * @param entry
211
+ * @return String
212
+ */
213
+ getZipEntryComment: function (/**Object*/ entry) {
214
+ var item = getEntry(entry);
215
+ if (item) {
216
+ return item.comment || "";
217
+ }
218
+ return "";
219
+ },
220
+
221
+ /**
222
+ * Updates the content of an existing entry inside the archive. The zip must be rewritten after updating the content
223
+ *
224
+ * @param entry
225
+ * @param content
226
+ */
227
+ updateFile: function (/**Object*/ entry, /**Buffer*/ content) {
228
+ var item = getEntry(entry);
229
+ if (item) {
230
+ item.setData(content);
231
+ }
232
+ },
233
+
234
+ /**
235
+ * Adds a file from the disk to the archive
236
+ *
237
+ * @param localPath File to add to zip
238
+ * @param zipPath Optional path inside the zip
239
+ * @param zipName Optional name for the file
240
+ */
241
+ addLocalFile: function (/**String*/ localPath, /**String=*/ zipPath, /**String=*/ zipName, /**String*/ comment) {
242
+ if (filetools.fs.existsSync(localPath)) {
243
+ // fix ZipPath
244
+ zipPath = zipPath ? fixPath(zipPath) : "";
245
+
246
+ // p - local file name
247
+ var p = localPath.split("\\").join("/").split("/").pop();
248
+
249
+ // add file name into zippath
250
+ zipPath += zipName ? zipName : p;
251
+
252
+ // read file attributes
253
+ const _attr = filetools.fs.statSync(localPath);
254
+
255
+ // add file into zip file
256
+ this.addFile(zipPath, filetools.fs.readFileSync(localPath), comment, _attr);
257
+ } else {
258
+ throw new Error(Utils.Errors.FILE_NOT_FOUND.replace("%s", localPath));
259
+ }
260
+ },
261
+
262
+ /**
263
+ * Adds a local directory and all its nested files and directories to the archive
264
+ *
265
+ * @param localPath
266
+ * @param zipPath optional path inside zip
267
+ * @param filter optional RegExp or Function if files match will
268
+ * be included.
269
+ */
270
+ addLocalFolder: function (/**String*/ localPath, /**String=*/ zipPath, /**=RegExp|Function*/ filter) {
271
+ // Prepare filter
272
+ if (filter instanceof RegExp) {
273
+ // if filter is RegExp wrap it
274
+ filter = (function (rx) {
275
+ return function (filename) {
276
+ return rx.test(filename);
277
+ };
278
+ })(filter);
279
+ } else if ("function" !== typeof filter) {
280
+ // if filter is not function we will replace it
281
+ filter = function () {
282
+ return true;
283
+ };
284
+ }
285
+
286
+ // fix ZipPath
287
+ zipPath = zipPath ? fixPath(zipPath) : "";
288
+
289
+ // normalize the path first
290
+ localPath = pth.normalize(localPath);
291
+
292
+ if (filetools.fs.existsSync(localPath)) {
293
+ const items = filetools.findFiles(localPath);
294
+ const self = this;
295
+
296
+ if (items.length) {
297
+ items.forEach(function (filepath) {
298
+ var p = pth.relative(localPath, filepath).split("\\").join("/"); //windows fix
299
+ if (filter(p)) {
300
+ var stats = filetools.fs.statSync(filepath);
301
+ if (stats.isFile()) {
302
+ self.addFile(zipPath + p, filetools.fs.readFileSync(filepath), "", stats);
303
+ } else {
304
+ self.addFile(zipPath + p + "/", Buffer.alloc(0), "", stats);
305
+ }
306
+ }
307
+ });
308
+ }
309
+ } else {
310
+ throw new Error(Utils.Errors.FILE_NOT_FOUND.replace("%s", localPath));
311
+ }
312
+ },
313
+
314
+ /**
315
+ * Asynchronous addLocalFile
316
+ * @param localPath
317
+ * @param callback
318
+ * @param zipPath optional path inside zip
319
+ * @param filter optional RegExp or Function if files match will
320
+ * be included.
321
+ */
322
+ addLocalFolderAsync: function (/*String*/ localPath, /*Function*/ callback, /*String*/ zipPath, /*RegExp|Function*/ filter) {
323
+ if (filter instanceof RegExp) {
324
+ filter = (function (rx) {
325
+ return function (filename) {
326
+ return rx.test(filename);
327
+ };
328
+ })(filter);
329
+ } else if ("function" !== typeof filter) {
330
+ filter = function () {
331
+ return true;
332
+ };
333
+ }
334
+
335
+ // fix ZipPath
336
+ zipPath = zipPath ? fixPath(zipPath) : "";
337
+
338
+ // normalize the path first
339
+ localPath = pth.normalize(localPath);
340
+
341
+ var self = this;
342
+ filetools.fs.open(localPath, "r", function (err) {
343
+ if (err && err.code === "ENOENT") {
344
+ callback(undefined, Utils.Errors.FILE_NOT_FOUND.replace("%s", localPath));
345
+ } else if (err) {
346
+ callback(undefined, err);
347
+ } else {
348
+ var items = filetools.findFiles(localPath);
349
+ var i = -1;
350
+
351
+ var next = function () {
352
+ i += 1;
353
+ if (i < items.length) {
354
+ var filepath = items[i];
355
+ var p = pth.relative(localPath, filepath).split("\\").join("/"); //windows fix
356
+ p = p
357
+ .normalize("NFD")
358
+ .replace(/[\u0300-\u036f]/g, "")
359
+ .replace(/[^\x20-\x7E]/g, ""); // accent fix
360
+ if (filter(p)) {
361
+ filetools.fs.stat(filepath, function (er0, stats) {
362
+ if (er0) callback(undefined, er0);
363
+ if (stats.isFile()) {
364
+ filetools.fs.readFile(filepath, function (er1, data) {
365
+ if (er1) {
366
+ callback(undefined, er1);
367
+ } else {
368
+ self.addFile(zipPath + p, data, "", stats);
369
+ next();
370
+ }
371
+ });
372
+ } else {
373
+ self.addFile(zipPath + p + "/", Buffer.alloc(0), "", stats);
374
+ next();
375
+ }
376
+ });
377
+ } else {
378
+ next();
379
+ }
380
+ } else {
381
+ callback(true, undefined);
382
+ }
383
+ };
384
+
385
+ next();
386
+ }
387
+ });
388
+ },
389
+
390
+ /**
391
+ *
392
+ * @param {string} localPath - path where files will be extracted
393
+ * @param {object} props - optional properties
394
+ * @param {string} props.zipPath - optional path inside zip
395
+ * @param {regexp, function} props.filter - RegExp or Function if files match will be included.
396
+ */
397
+ addLocalFolderPromise: function (/*String*/ localPath, /* object */ props) {
398
+ return new Promise((resolve, reject) => {
399
+ const { filter, zipPath } = Object.assign({}, props);
400
+ this.addLocalFolderAsync(
401
+ localPath,
402
+ (done, err) => {
403
+ if (err) reject(err);
404
+ if (done) resolve(this);
405
+ },
406
+ zipPath,
407
+ filter
408
+ );
409
+ });
410
+ },
411
+
412
+ /**
413
+ * Allows you to create a entry (file or directory) in the zip file.
414
+ * If you want to create a directory the entryName must end in / and a null buffer should be provided.
415
+ * Comment and attributes are optional
416
+ *
417
+ * @param {string} entryName
418
+ * @param {Buffer | string} content - file content as buffer or utf8 coded string
419
+ * @param {string} comment - file comment
420
+ * @param {number | object} attr - number as unix file permissions, object as filesystem Stats object
421
+ */
422
+ addFile: function (/**String*/ entryName, /**Buffer*/ content, /**String*/ comment, /**Number*/ attr) {
423
+ let entry = getEntry(entryName);
424
+ const update = entry != null;
425
+
426
+ // prepare new entry
427
+ if (!update) {
428
+ entry = new ZipEntry();
429
+ entry.entryName = entryName;
430
+ }
431
+ entry.comment = comment || "";
432
+
433
+ const isStat = "object" === typeof attr && attr instanceof filetools.fs.Stats;
434
+
435
+ // last modification time from file stats
436
+ if (isStat) {
437
+ entry.header.time = attr.mtime;
438
+ }
439
+
440
+ // Set file attribute
441
+ var fileattr = entry.isDirectory ? 0x10 : 0; // (MS-DOS directory flag)
442
+
443
+ // extended attributes field for Unix
444
+ if (!Utils.isWin) {
445
+ // set file type either S_IFDIR / S_IFREG
446
+ let unix = entry.isDirectory ? 0x4000 : 0x8000;
447
+
448
+ if (isStat) {
449
+ // File attributes from file stats
450
+ unix |= 0xfff & attr.mode;
451
+ } else if ("number" === typeof attr) {
452
+ // attr from given attr values
453
+ unix |= 0xfff & attr;
454
+ } else {
455
+ // Default values:
456
+ unix |= entry.isDirectory ? 0o755 : 0o644; // permissions (drwxr-xr-x) or (-r-wr--r--)
457
+ }
458
+
459
+ fileattr = (fileattr | (unix << 16)) >>> 0; // add attributes
460
+ }
461
+
462
+ entry.attr = fileattr;
463
+
464
+ entry.setData(content);
465
+ if (!update) _zip.setEntry(entry);
466
+ },
467
+
468
+ /**
469
+ * Returns an array of ZipEntry objects representing the files and folders inside the archive
470
+ *
471
+ * @return Array
472
+ */
473
+ getEntries: function () {
474
+ return _zip ? _zip.entries : [];
475
+ },
476
+
477
+ /**
478
+ * Returns a ZipEntry object representing the file or folder specified by ``name``.
479
+ *
480
+ * @param name
481
+ * @return ZipEntry
482
+ */
483
+ getEntry: function (/**String*/ name) {
484
+ return getEntry(name);
485
+ },
486
+
487
+ getEntryCount: function () {
488
+ return _zip.getEntryCount();
489
+ },
490
+
491
+ forEach: function (callback) {
492
+ return _zip.forEach(callback);
493
+ },
494
+
495
+ /**
496
+ * Extracts the given entry to the given targetPath
497
+ * If the entry is a directory inside the archive, the entire directory and it's subdirectories will be extracted
498
+ *
499
+ * @param entry ZipEntry object or String with the full path of the entry
500
+ * @param targetPath Target folder where to write the file
501
+ * @param maintainEntryPath If maintainEntryPath is true and the entry is inside a folder, the entry folder
502
+ * will be created in targetPath as well. Default is TRUE
503
+ * @param overwrite If the file already exists at the target path, the file will be overwriten if this is true.
504
+ * Default is FALSE
505
+ * @param keepOriginalPermission The file will be set as the permission from the entry if this is true.
506
+ * Default is FALSE
507
+ * @param outFileName String If set will override the filename of the extracted file (Only works if the entry is a file)
508
+ *
509
+ * @return Boolean
510
+ */
511
+ extractEntryTo: function (
512
+ /**Object*/ entry,
513
+ /**String*/ targetPath,
514
+ /**Boolean*/ maintainEntryPath,
515
+ /**Boolean*/ overwrite,
516
+ /**Boolean*/ keepOriginalPermission,
517
+ /**String**/ outFileName
518
+ ) {
519
+ overwrite = get_Bool(overwrite, false);
520
+ keepOriginalPermission = get_Bool(keepOriginalPermission, false);
521
+ maintainEntryPath = get_Bool(maintainEntryPath, true);
522
+ outFileName = get_Str(outFileName, get_Str(keepOriginalPermission, undefined));
523
+
524
+ var item = getEntry(entry);
525
+ if (!item) {
526
+ throw new Error(Utils.Errors.NO_ENTRY);
527
+ }
528
+
529
+ var entryName = canonical(item.entryName);
530
+
531
+ var target = sanitize(targetPath, outFileName && !item.isDirectory ? outFileName : maintainEntryPath ? entryName : pth.basename(entryName));
532
+
533
+ if (item.isDirectory) {
534
+ var children = _zip.getEntryChildren(item);
535
+ children.forEach(function (child) {
536
+ if (child.isDirectory) return;
537
+ var content = child.getData();
538
+ if (!content) {
539
+ throw new Error(Utils.Errors.CANT_EXTRACT_FILE);
540
+ }
541
+ var name = canonical(child.entryName);
542
+ var childName = sanitize(targetPath, maintainEntryPath ? name : pth.basename(name));
543
+ // The reverse operation for attr depend on method addFile()
544
+ const fileAttr = keepOriginalPermission ? child.header.fileAttr : undefined;
545
+ filetools.writeFileTo(childName, content, overwrite, fileAttr);
546
+ });
547
+ return true;
548
+ }
549
+
550
+ var content = item.getData();
551
+ if (!content) throw new Error(Utils.Errors.CANT_EXTRACT_FILE);
552
+
553
+ if (filetools.fs.existsSync(target) && !overwrite) {
554
+ throw new Error(Utils.Errors.CANT_OVERRIDE);
555
+ }
556
+ // The reverse operation for attr depend on method addFile()
557
+ const fileAttr = keepOriginalPermission ? entry.header.fileAttr : undefined;
558
+ filetools.writeFileTo(target, content, overwrite, fileAttr);
559
+
560
+ return true;
561
+ },
562
+
563
+ /**
564
+ * Test the archive
565
+ *
566
+ */
567
+ test: function (pass) {
568
+ if (!_zip) {
569
+ return false;
570
+ }
571
+
572
+ for (var entry in _zip.entries) {
573
+ try {
574
+ if (entry.isDirectory) {
575
+ continue;
576
+ }
577
+ var content = _zip.entries[entry].getData(pass);
578
+ if (!content) {
579
+ return false;
580
+ }
581
+ } catch (err) {
582
+ return false;
583
+ }
584
+ }
585
+ return true;
586
+ },
587
+
588
+ /**
589
+ * Extracts the entire archive to the given location
590
+ *
591
+ * @param targetPath Target location
592
+ * @param overwrite If the file already exists at the target path, the file will be overwriten if this is true.
593
+ * Default is FALSE
594
+ * @param keepOriginalPermission The file will be set as the permission from the entry if this is true.
595
+ * Default is FALSE
596
+ */
597
+ extractAllTo: function (/**String*/ targetPath, /**Boolean*/ overwrite, /**Boolean*/ keepOriginalPermission, /*String, Buffer*/ pass) {
598
+ overwrite = get_Bool(overwrite, false);
599
+ pass = get_Str(keepOriginalPermission, pass);
600
+ keepOriginalPermission = get_Bool(keepOriginalPermission, false);
601
+ if (!_zip) {
602
+ throw new Error(Utils.Errors.NO_ZIP);
603
+ }
604
+ _zip.entries.forEach(function (entry) {
605
+ var entryName = sanitize(targetPath, canonical(entry.entryName.toString()));
606
+ if (entry.isDirectory) {
607
+ filetools.makeDir(entryName);
608
+ return;
609
+ }
610
+ var content = entry.getData(pass);
611
+ if (!content) {
612
+ throw new Error(Utils.Errors.CANT_EXTRACT_FILE);
613
+ }
614
+ // The reverse operation for attr depend on method addFile()
615
+ const fileAttr = keepOriginalPermission ? entry.header.fileAttr : undefined;
616
+ filetools.writeFileTo(entryName, content, overwrite, fileAttr);
617
+ try {
618
+ filetools.fs.utimesSync(entryName, entry.header.time, entry.header.time);
619
+ } catch (err) {
620
+ throw new Error(Utils.Errors.CANT_EXTRACT_FILE);
621
+ }
622
+ });
623
+ },
624
+
625
+ /**
626
+ * Asynchronous extractAllTo
627
+ *
628
+ * @param targetPath Target location
629
+ * @param overwrite If the file already exists at the target path, the file will be overwriten if this is true.
630
+ * Default is FALSE
631
+ * @param keepOriginalPermission The file will be set as the permission from the entry if this is true.
632
+ * Default is FALSE
633
+ * @param callback The callback will be executed when all entries are extracted successfully or any error is thrown.
634
+ */
635
+ extractAllToAsync: function (/**String*/ targetPath, /**Boolean*/ overwrite, /**Boolean*/ keepOriginalPermission, /**Function*/ callback) {
636
+ if (!callback) {
637
+ callback = function () {};
638
+ }
639
+ overwrite = get_Bool(overwrite, false);
640
+ if (typeof keepOriginalPermission === "function" && !callback) callback = keepOriginalPermission;
641
+ keepOriginalPermission = get_Bool(keepOriginalPermission, false);
642
+ if (!_zip) {
643
+ callback(new Error(Utils.Errors.NO_ZIP));
644
+ return;
645
+ }
646
+
647
+ targetPath = pth.resolve(targetPath);
648
+ // convert entryName to
649
+ const getPath = (entry) => sanitize(targetPath, pth.normalize(canonical(entry.entryName.toString())));
650
+ const getError = (msg, file) => new Error(msg + ': "' + file + '"');
651
+
652
+ // separate directories from files
653
+ const dirEntries = [];
654
+ const fileEntries = new Set();
655
+ _zip.entries.forEach((e) => {
656
+ if (e.isDirectory) {
657
+ dirEntries.push(e);
658
+ } else {
659
+ fileEntries.add(e);
660
+ }
661
+ });
662
+
663
+ // Create directory entries first synchronously
664
+ // this prevents race condition and assures folders are there before writing files
665
+ for (const entry of dirEntries) {
666
+ const dirPath = getPath(entry);
667
+ // The reverse operation for attr depend on method addFile()
668
+ const dirAttr = keepOriginalPermission ? entry.header.fileAttr : undefined;
669
+ try {
670
+ filetools.makeDir(dirPath);
671
+ if (dirAttr) filetools.fs.chmodSync(dirPath, dirAttr);
672
+ // in unix timestamp will change if files are later added to folder, but still
673
+ filetools.fs.utimesSync(dirPath, entry.header.time, entry.header.time);
674
+ } catch (er) {
675
+ callback(getError("Unable to create folder", dirPath));
676
+ }
677
+ }
678
+
679
+ // callback wrapper, for some house keeping
680
+ const done = () => {
681
+ if (fileEntries.size === 0) {
682
+ callback();
683
+ }
684
+ };
685
+
686
+ // Extract file entries asynchronously
687
+ for (const entry of fileEntries.values()) {
688
+ const entryName = pth.normalize(canonical(entry.entryName.toString()));
689
+ const filePath = sanitize(targetPath, entryName);
690
+ entry.getDataAsync(function (content, err_1) {
691
+ if (err_1) {
692
+ callback(new Error(err_1));
693
+ return;
694
+ }
695
+ if (!content) {
696
+ callback(new Error(Utils.Errors.CANT_EXTRACT_FILE));
697
+ } else {
698
+ // The reverse operation for attr depend on method addFile()
699
+ const fileAttr = keepOriginalPermission ? entry.header.fileAttr : undefined;
700
+ filetools.writeFileToAsync(filePath, content, overwrite, fileAttr, function (succ) {
701
+ if (!succ) {
702
+ callback(getError("Unable to write file", filePath));
703
+ return;
704
+ }
705
+ filetools.fs.utimes(filePath, entry.header.time, entry.header.time, function (err_2) {
706
+ if (err_2) {
707
+ callback(getError("Unable to set times", filePath));
708
+ return;
709
+ }
710
+ fileEntries.delete(entry);
711
+ // call the callback if it was last entry
712
+ done();
713
+ });
714
+ });
715
+ }
716
+ });
717
+ }
718
+ // call the callback if fileEntries was empty
719
+ done();
720
+ },
721
+
722
+ /**
723
+ * Writes the newly created zip file to disk at the specified location or if a zip was opened and no ``targetFileName`` is provided, it will overwrite the opened zip
724
+ *
725
+ * @param targetFileName
726
+ * @param callback
727
+ */
728
+ writeZip: function (/**String*/ targetFileName, /**Function*/ callback) {
729
+ if (arguments.length === 1) {
730
+ if (typeof targetFileName === "function") {
731
+ callback = targetFileName;
732
+ targetFileName = "";
733
+ }
734
+ }
735
+
736
+ if (!targetFileName && opts.filename) {
737
+ targetFileName = opts.filename;
738
+ }
739
+ if (!targetFileName) return;
740
+
741
+ var zipData = _zip.compressToBuffer();
742
+ if (zipData) {
743
+ var ok = filetools.writeFileTo(targetFileName, zipData, true);
744
+ if (typeof callback === "function") callback(!ok ? new Error("failed") : null, "");
745
+ }
746
+ },
747
+
748
+ writeZipPromise: function (/**String*/ targetFileName, /* object */ props) {
749
+ const { overwrite, perm } = Object.assign({ overwrite: true }, props);
750
+
751
+ return new Promise((resolve, reject) => {
752
+ // find file name
753
+ if (!targetFileName && opts.filename) targetFileName = opts.filename;
754
+ if (!targetFileName) reject("ADM-ZIP: ZIP File Name Missing");
755
+
756
+ this.toBufferPromise().then((zipData) => {
757
+ const ret = (done) => (done ? resolve(done) : reject("ADM-ZIP: Wasn't able to write zip file"));
758
+ filetools.writeFileToAsync(targetFileName, zipData, overwrite, perm, ret);
759
+ }, reject);
760
+ });
761
+ },
762
+
763
+ toBufferPromise: function () {
764
+ return new Promise((resolve, reject) => {
765
+ _zip.toAsyncBuffer(resolve, reject);
766
+ });
767
+ },
768
+
769
+ /**
770
+ * Returns the content of the entire zip file as a Buffer object
771
+ *
772
+ * @return Buffer
773
+ */
774
+ toBuffer: function (/**Function=*/ onSuccess, /**Function=*/ onFail, /**Function=*/ onItemStart, /**Function=*/ onItemEnd) {
775
+ this.valueOf = 2;
776
+ if (typeof onSuccess === "function") {
777
+ _zip.toAsyncBuffer(onSuccess, onFail, onItemStart, onItemEnd);
778
+ return null;
779
+ }
780
+ return _zip.compressToBuffer();
781
+ }
782
+ };
783
+ };