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,384 @@
1
+ const ZipEntry = require("./zipEntry");
2
+ const Headers = require("./headers");
3
+ const Utils = require("./util");
4
+
5
+ module.exports = function (/*Buffer|null*/ inBuffer, /** object */ options) {
6
+ var entryList = [],
7
+ entryTable = {},
8
+ _comment = Buffer.alloc(0),
9
+ mainHeader = new Headers.MainHeader(),
10
+ loadedEntries = false;
11
+
12
+ // assign options
13
+ const opts = Object.assign(Object.create(null), options);
14
+
15
+ const { noSort } = opts;
16
+
17
+ if (inBuffer) {
18
+ // is a memory buffer
19
+ readMainHeader(opts.readEntries);
20
+ } else {
21
+ // none. is a new file
22
+ loadedEntries = true;
23
+ }
24
+
25
+ function iterateEntries(callback) {
26
+ const totalEntries = mainHeader.diskEntries; // total number of entries
27
+ let index = mainHeader.offset; // offset of first CEN header
28
+
29
+ for (let i = 0; i < totalEntries; i++) {
30
+ let tmp = index;
31
+ const entry = new ZipEntry(inBuffer);
32
+
33
+ entry.header = inBuffer.slice(tmp, (tmp += Utils.Constants.CENHDR));
34
+ entry.entryName = inBuffer.slice(tmp, (tmp += entry.header.fileNameLength));
35
+
36
+ index += entry.header.entryHeaderSize;
37
+
38
+ callback(entry);
39
+ }
40
+ }
41
+
42
+ function readEntries() {
43
+ loadedEntries = true;
44
+ entryTable = {};
45
+ entryList = new Array(mainHeader.diskEntries); // total number of entries
46
+ var index = mainHeader.offset; // offset of first CEN header
47
+ for (var i = 0; i < entryList.length; i++) {
48
+ var tmp = index,
49
+ entry = new ZipEntry(inBuffer);
50
+ entry.header = inBuffer.slice(tmp, (tmp += Utils.Constants.CENHDR));
51
+
52
+ entry.entryName = inBuffer.slice(tmp, (tmp += entry.header.fileNameLength));
53
+
54
+ if (entry.header.extraLength) {
55
+ entry.extra = inBuffer.slice(tmp, (tmp += entry.header.extraLength));
56
+ }
57
+
58
+ if (entry.header.commentLength) entry.comment = inBuffer.slice(tmp, tmp + entry.header.commentLength);
59
+
60
+ index += entry.header.entryHeaderSize;
61
+
62
+ entryList[i] = entry;
63
+ entryTable[entry.entryName] = entry;
64
+ }
65
+ }
66
+
67
+ function readMainHeader(/*Boolean*/ readNow) {
68
+ var i = inBuffer.length - Utils.Constants.ENDHDR, // END header size
69
+ max = Math.max(0, i - 0xffff), // 0xFFFF is the max zip file comment length
70
+ n = max,
71
+ endStart = inBuffer.length,
72
+ endOffset = -1, // Start offset of the END header
73
+ commentEnd = 0;
74
+
75
+ for (i; i >= n; i--) {
76
+ if (inBuffer[i] !== 0x50) continue; // quick check that the byte is 'P'
77
+ if (inBuffer.readUInt32LE(i) === Utils.Constants.ENDSIG) {
78
+ // "PK\005\006"
79
+ endOffset = i;
80
+ commentEnd = i;
81
+ endStart = i + Utils.Constants.ENDHDR;
82
+ // We already found a regular signature, let's look just a bit further to check if there's any zip64 signature
83
+ n = i - Utils.Constants.END64HDR;
84
+ continue;
85
+ }
86
+
87
+ if (inBuffer.readUInt32LE(i) === Utils.Constants.END64SIG) {
88
+ // Found a zip64 signature, let's continue reading the whole zip64 record
89
+ n = max;
90
+ continue;
91
+ }
92
+
93
+ if (inBuffer.readUInt32LE(i) === Utils.Constants.ZIP64SIG) {
94
+ // Found the zip64 record, let's determine it's size
95
+ endOffset = i;
96
+ endStart = i + Utils.readBigUInt64LE(inBuffer, i + Utils.Constants.ZIP64SIZE) + Utils.Constants.ZIP64LEAD;
97
+ break;
98
+ }
99
+ }
100
+
101
+ if (!~endOffset) throw new Error(Utils.Errors.INVALID_FORMAT);
102
+
103
+ mainHeader.loadFromBinary(inBuffer.slice(endOffset, endStart));
104
+ if (mainHeader.commentLength) {
105
+ _comment = inBuffer.slice(commentEnd + Utils.Constants.ENDHDR);
106
+ }
107
+ if (readNow) readEntries();
108
+ }
109
+
110
+ function sortEntries() {
111
+ if (entryList.length > 1 && !noSort) {
112
+ entryList.sort((a, b) => a.entryName.toLowerCase().localeCompare(b.entryName.toLowerCase()));
113
+ }
114
+ }
115
+
116
+ return {
117
+ /**
118
+ * Returns an array of ZipEntry objects existent in the current opened archive
119
+ * @return Array
120
+ */
121
+ get entries() {
122
+ if (!loadedEntries) {
123
+ readEntries();
124
+ }
125
+ return entryList;
126
+ },
127
+
128
+ /**
129
+ * Archive comment
130
+ * @return {String}
131
+ */
132
+ get comment() {
133
+ return _comment.toString();
134
+ },
135
+ set comment(val) {
136
+ _comment = Utils.toBuffer(val);
137
+ mainHeader.commentLength = _comment.length;
138
+ },
139
+
140
+ getEntryCount: function () {
141
+ if (!loadedEntries) {
142
+ return mainHeader.diskEntries;
143
+ }
144
+
145
+ return entryList.length;
146
+ },
147
+
148
+ forEach: function (callback) {
149
+ if (!loadedEntries) {
150
+ iterateEntries(callback);
151
+ return;
152
+ }
153
+
154
+ entryList.forEach(callback);
155
+ },
156
+
157
+ /**
158
+ * Returns a reference to the entry with the given name or null if entry is inexistent
159
+ *
160
+ * @param entryName
161
+ * @return ZipEntry
162
+ */
163
+ getEntry: function (/*String*/ entryName) {
164
+ if (!loadedEntries) {
165
+ readEntries();
166
+ }
167
+ return entryTable[entryName] || null;
168
+ },
169
+
170
+ /**
171
+ * Adds the given entry to the entry list
172
+ *
173
+ * @param entry
174
+ */
175
+ setEntry: function (/*ZipEntry*/ entry) {
176
+ if (!loadedEntries) {
177
+ readEntries();
178
+ }
179
+ entryList.push(entry);
180
+ entryTable[entry.entryName] = entry;
181
+ mainHeader.totalEntries = entryList.length;
182
+ },
183
+
184
+ /**
185
+ * Removes the entry with the given name from the entry list.
186
+ *
187
+ * If the entry is a directory, then all nested files and directories will be removed
188
+ * @param entryName
189
+ */
190
+ deleteEntry: function (/*String*/ entryName) {
191
+ if (!loadedEntries) {
192
+ readEntries();
193
+ }
194
+ var entry = entryTable[entryName];
195
+ if (entry && entry.isDirectory) {
196
+ var _self = this;
197
+ this.getEntryChildren(entry).forEach(function (child) {
198
+ if (child.entryName !== entryName) {
199
+ _self.deleteEntry(child.entryName);
200
+ }
201
+ });
202
+ }
203
+ entryList.splice(entryList.indexOf(entry), 1);
204
+ delete entryTable[entryName];
205
+ mainHeader.totalEntries = entryList.length;
206
+ },
207
+
208
+ /**
209
+ * Iterates and returns all nested files and directories of the given entry
210
+ *
211
+ * @param entry
212
+ * @return Array
213
+ */
214
+ getEntryChildren: function (/*ZipEntry*/ entry) {
215
+ if (!loadedEntries) {
216
+ readEntries();
217
+ }
218
+ if (entry && entry.isDirectory) {
219
+ const list = [];
220
+ const name = entry.entryName;
221
+ const len = name.length;
222
+
223
+ entryList.forEach(function (zipEntry) {
224
+ if (zipEntry.entryName.substr(0, len) === name) {
225
+ list.push(zipEntry);
226
+ }
227
+ });
228
+ return list;
229
+ }
230
+ return [];
231
+ },
232
+
233
+ /**
234
+ * Returns the zip file
235
+ *
236
+ * @return Buffer
237
+ */
238
+ compressToBuffer: function () {
239
+ if (!loadedEntries) {
240
+ readEntries();
241
+ }
242
+ sortEntries();
243
+
244
+ const dataBlock = [];
245
+ const entryHeaders = [];
246
+ let totalSize = 0;
247
+ let dindex = 0;
248
+
249
+ mainHeader.size = 0;
250
+ mainHeader.offset = 0;
251
+
252
+ for (const entry of entryList) {
253
+ // compress data and set local and entry header accordingly. Reason why is called first
254
+ const compressedData = entry.getCompressedData();
255
+ // 1. construct data header
256
+ entry.header.offset = dindex;
257
+ const dataHeader = entry.header.dataHeaderToBinary();
258
+ const entryNameLen = entry.rawEntryName.length;
259
+ // 1.2. postheader - data after data header
260
+ const postHeader = Buffer.alloc(entryNameLen + entry.extra.length);
261
+ entry.rawEntryName.copy(postHeader, 0);
262
+ postHeader.copy(entry.extra, entryNameLen);
263
+
264
+ // 2. offsets
265
+ const dataLength = dataHeader.length + postHeader.length + compressedData.length;
266
+ dindex += dataLength;
267
+
268
+ // 3. store values in sequence
269
+ dataBlock.push(dataHeader);
270
+ dataBlock.push(postHeader);
271
+ dataBlock.push(compressedData);
272
+
273
+ // 4. construct entry header
274
+ const entryHeader = entry.packHeader();
275
+ entryHeaders.push(entryHeader);
276
+ // 5. update main header
277
+ mainHeader.size += entryHeader.length;
278
+ totalSize += dataLength + entryHeader.length;
279
+ }
280
+
281
+ totalSize += mainHeader.mainHeaderSize; // also includes zip file comment length
282
+ // point to end of data and beginning of central directory first record
283
+ mainHeader.offset = dindex;
284
+
285
+ dindex = 0;
286
+ const outBuffer = Buffer.alloc(totalSize);
287
+ // write data blocks
288
+ for (const content of dataBlock) {
289
+ content.copy(outBuffer, dindex);
290
+ dindex += content.length;
291
+ }
292
+
293
+ // write central directory entries
294
+ for (const content of entryHeaders) {
295
+ content.copy(outBuffer, dindex);
296
+ dindex += content.length;
297
+ }
298
+
299
+ // write main header
300
+ const mh = mainHeader.toBinary();
301
+ if (_comment) {
302
+ _comment.copy(mh, Utils.Constants.ENDHDR); // add zip file comment
303
+ }
304
+ mh.copy(outBuffer, dindex);
305
+
306
+ return outBuffer;
307
+ },
308
+
309
+ toAsyncBuffer: function (/*Function*/ onSuccess, /*Function*/ onFail, /*Function*/ onItemStart, /*Function*/ onItemEnd) {
310
+ try {
311
+ if (!loadedEntries) {
312
+ readEntries();
313
+ }
314
+ sortEntries();
315
+
316
+ const dataBlock = [];
317
+ const entryHeaders = [];
318
+ let totalSize = 0;
319
+ let dindex = 0;
320
+
321
+ mainHeader.size = 0;
322
+ mainHeader.offset = 0;
323
+
324
+ const compress2Buffer = function (entryLists) {
325
+ if (entryLists.length) {
326
+ const entry = entryLists.pop();
327
+ const name = entry.entryName + entry.extra.toString();
328
+ if (onItemStart) onItemStart(name);
329
+ entry.getCompressedDataAsync(function (compressedData) {
330
+ if (onItemEnd) onItemEnd(name);
331
+
332
+ entry.header.offset = dindex;
333
+ // data header
334
+ const dataHeader = entry.header.dataHeaderToBinary();
335
+ const postHeader = Buffer.alloc(name.length, name);
336
+ const dataLength = dataHeader.length + postHeader.length + compressedData.length;
337
+
338
+ dindex += dataLength;
339
+
340
+ dataBlock.push(dataHeader);
341
+ dataBlock.push(postHeader);
342
+ dataBlock.push(compressedData);
343
+
344
+ const entryHeader = entry.packHeader();
345
+ entryHeaders.push(entryHeader);
346
+ mainHeader.size += entryHeader.length;
347
+ totalSize += dataLength + entryHeader.length;
348
+
349
+ compress2Buffer(entryLists);
350
+ });
351
+ } else {
352
+ totalSize += mainHeader.mainHeaderSize; // also includes zip file comment length
353
+ // point to end of data and beginning of central directory first record
354
+ mainHeader.offset = dindex;
355
+
356
+ dindex = 0;
357
+ const outBuffer = Buffer.alloc(totalSize);
358
+ dataBlock.forEach(function (content) {
359
+ content.copy(outBuffer, dindex); // write data blocks
360
+ dindex += content.length;
361
+ });
362
+ entryHeaders.forEach(function (content) {
363
+ content.copy(outBuffer, dindex); // write central directory entries
364
+ dindex += content.length;
365
+ });
366
+
367
+ const mh = mainHeader.toBinary();
368
+ if (_comment) {
369
+ _comment.copy(mh, Utils.Constants.ENDHDR); // add zip file comment
370
+ }
371
+
372
+ mh.copy(outBuffer, dindex); // write main header
373
+
374
+ onSuccess(outBuffer);
375
+ }
376
+ };
377
+
378
+ compress2Buffer(entryList);
379
+ } catch (e) {
380
+ onFail(e);
381
+ }
382
+ }
383
+ };
384
+ };
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Alex Indigo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,233 @@
1
+ # asynckit [![NPM Module](https://img.shields.io/npm/v/asynckit.svg?style=flat)](https://www.npmjs.com/package/asynckit)
2
+
3
+ Minimal async jobs utility library, with streams support.
4
+
5
+ [![PhantomJS Build](https://img.shields.io/travis/alexindigo/asynckit/v0.4.0.svg?label=browser&style=flat)](https://travis-ci.org/alexindigo/asynckit)
6
+ [![Linux Build](https://img.shields.io/travis/alexindigo/asynckit/v0.4.0.svg?label=linux:0.12-6.x&style=flat)](https://travis-ci.org/alexindigo/asynckit)
7
+ [![Windows Build](https://img.shields.io/appveyor/ci/alexindigo/asynckit/v0.4.0.svg?label=windows:0.12-6.x&style=flat)](https://ci.appveyor.com/project/alexindigo/asynckit)
8
+
9
+ [![Coverage Status](https://img.shields.io/coveralls/alexindigo/asynckit/v0.4.0.svg?label=code+coverage&style=flat)](https://coveralls.io/github/alexindigo/asynckit?branch=master)
10
+ [![Dependency Status](https://img.shields.io/david/alexindigo/asynckit/v0.4.0.svg?style=flat)](https://david-dm.org/alexindigo/asynckit)
11
+ [![bitHound Overall Score](https://www.bithound.io/github/alexindigo/asynckit/badges/score.svg)](https://www.bithound.io/github/alexindigo/asynckit)
12
+
13
+ <!-- [![Readme](https://img.shields.io/badge/readme-tested-brightgreen.svg?style=flat)](https://www.npmjs.com/package/reamde) -->
14
+
15
+ AsyncKit provides harness for `parallel` and `serial` iterators over list of items represented by arrays or objects.
16
+ Optionally it accepts abort function (should be synchronously return by iterator for each item), and terminates left over jobs upon an error event. For specific iteration order built-in (`ascending` and `descending`) and custom sort helpers also supported, via `asynckit.serialOrdered` method.
17
+
18
+ It ensures async operations to keep behavior more stable and prevent `Maximum call stack size exceeded` errors, from sync iterators.
19
+
20
+ | compression | size |
21
+ | :----------------- | -------: |
22
+ | asynckit.js | 12.34 kB |
23
+ | asynckit.min.js | 4.11 kB |
24
+ | asynckit.min.js.gz | 1.47 kB |
25
+
26
+
27
+ ## Install
28
+
29
+ ```sh
30
+ $ npm install --save asynckit
31
+ ```
32
+
33
+ ## Examples
34
+
35
+ ### Parallel Jobs
36
+
37
+ Runs iterator over provided array in parallel. Stores output in the `result` array,
38
+ on the matching positions. In unlikely event of an error from one of the jobs,
39
+ will terminate rest of the active jobs (if abort function is provided)
40
+ and return error along with salvaged data to the main callback function.
41
+
42
+ #### Input Array
43
+
44
+ ```javascript
45
+ var parallel = require('asynckit').parallel
46
+ , assert = require('assert')
47
+ ;
48
+
49
+ var source = [ 1, 1, 4, 16, 64, 32, 8, 2 ]
50
+ , expectedResult = [ 2, 2, 8, 32, 128, 64, 16, 4 ]
51
+ , expectedTarget = [ 1, 1, 2, 4, 8, 16, 32, 64 ]
52
+ , target = []
53
+ ;
54
+
55
+ parallel(source, asyncJob, function(err, result)
56
+ {
57
+ assert.deepEqual(result, expectedResult);
58
+ assert.deepEqual(target, expectedTarget);
59
+ });
60
+
61
+ // async job accepts one element from the array
62
+ // and a callback function
63
+ function asyncJob(item, cb)
64
+ {
65
+ // different delays (in ms) per item
66
+ var delay = item * 25;
67
+
68
+ // pretend different jobs take different time to finish
69
+ // and not in consequential order
70
+ var timeoutId = setTimeout(function() {
71
+ target.push(item);
72
+ cb(null, item * 2);
73
+ }, delay);
74
+
75
+ // allow to cancel "leftover" jobs upon error
76
+ // return function, invoking of which will abort this job
77
+ return clearTimeout.bind(null, timeoutId);
78
+ }
79
+ ```
80
+
81
+ More examples could be found in [test/test-parallel-array.js](test/test-parallel-array.js).
82
+
83
+ #### Input Object
84
+
85
+ Also it supports named jobs, listed via object.
86
+
87
+ ```javascript
88
+ var parallel = require('asynckit/parallel')
89
+ , assert = require('assert')
90
+ ;
91
+
92
+ var source = { first: 1, one: 1, four: 4, sixteen: 16, sixtyFour: 64, thirtyTwo: 32, eight: 8, two: 2 }
93
+ , expectedResult = { first: 2, one: 2, four: 8, sixteen: 32, sixtyFour: 128, thirtyTwo: 64, eight: 16, two: 4 }
94
+ , expectedTarget = [ 1, 1, 2, 4, 8, 16, 32, 64 ]
95
+ , expectedKeys = [ 'first', 'one', 'two', 'four', 'eight', 'sixteen', 'thirtyTwo', 'sixtyFour' ]
96
+ , target = []
97
+ , keys = []
98
+ ;
99
+
100
+ parallel(source, asyncJob, function(err, result)
101
+ {
102
+ assert.deepEqual(result, expectedResult);
103
+ assert.deepEqual(target, expectedTarget);
104
+ assert.deepEqual(keys, expectedKeys);
105
+ });
106
+
107
+ // supports full value, key, callback (shortcut) interface
108
+ function asyncJob(item, key, cb)
109
+ {
110
+ // different delays (in ms) per item
111
+ var delay = item * 25;
112
+
113
+ // pretend different jobs take different time to finish
114
+ // and not in consequential order
115
+ var timeoutId = setTimeout(function() {
116
+ keys.push(key);
117
+ target.push(item);
118
+ cb(null, item * 2);
119
+ }, delay);
120
+
121
+ // allow to cancel "leftover" jobs upon error
122
+ // return function, invoking of which will abort this job
123
+ return clearTimeout.bind(null, timeoutId);
124
+ }
125
+ ```
126
+
127
+ More examples could be found in [test/test-parallel-object.js](test/test-parallel-object.js).
128
+
129
+ ### Serial Jobs
130
+
131
+ Runs iterator over provided array sequentially. Stores output in the `result` array,
132
+ on the matching positions. In unlikely event of an error from one of the jobs,
133
+ will not proceed to the rest of the items in the list
134
+ and return error along with salvaged data to the main callback function.
135
+
136
+ #### Input Array
137
+
138
+ ```javascript
139
+ var serial = require('asynckit/serial')
140
+ , assert = require('assert')
141
+ ;
142
+
143
+ var source = [ 1, 1, 4, 16, 64, 32, 8, 2 ]
144
+ , expectedResult = [ 2, 2, 8, 32, 128, 64, 16, 4 ]
145
+ , expectedTarget = [ 0, 1, 2, 3, 4, 5, 6, 7 ]
146
+ , target = []
147
+ ;
148
+
149
+ serial(source, asyncJob, function(err, result)
150
+ {
151
+ assert.deepEqual(result, expectedResult);
152
+ assert.deepEqual(target, expectedTarget);
153
+ });
154
+
155
+ // extended interface (item, key, callback)
156
+ // also supported for arrays
157
+ function asyncJob(item, key, cb)
158
+ {
159
+ target.push(key);
160
+
161
+ // it will be automatically made async
162
+ // even it iterator "returns" in the same event loop
163
+ cb(null, item * 2);
164
+ }
165
+ ```
166
+
167
+ More examples could be found in [test/test-serial-array.js](test/test-serial-array.js).
168
+
169
+ #### Input Object
170
+
171
+ Also it supports named jobs, listed via object.
172
+
173
+ ```javascript
174
+ var serial = require('asynckit').serial
175
+ , assert = require('assert')
176
+ ;
177
+
178
+ var source = [ 1, 1, 4, 16, 64, 32, 8, 2 ]
179
+ , expectedResult = [ 2, 2, 8, 32, 128, 64, 16, 4 ]
180
+ , expectedTarget = [ 0, 1, 2, 3, 4, 5, 6, 7 ]
181
+ , target = []
182
+ ;
183
+
184
+ var source = { first: 1, one: 1, four: 4, sixteen: 16, sixtyFour: 64, thirtyTwo: 32, eight: 8, two: 2 }
185
+ , expectedResult = { first: 2, one: 2, four: 8, sixteen: 32, sixtyFour: 128, thirtyTwo: 64, eight: 16, two: 4 }
186
+ , expectedTarget = [ 1, 1, 4, 16, 64, 32, 8, 2 ]
187
+ , target = []
188
+ ;
189
+
190
+
191
+ serial(source, asyncJob, function(err, result)
192
+ {
193
+ assert.deepEqual(result, expectedResult);
194
+ assert.deepEqual(target, expectedTarget);
195
+ });
196
+
197
+ // shortcut interface (item, callback)
198
+ // works for object as well as for the arrays
199
+ function asyncJob(item, cb)
200
+ {
201
+ target.push(item);
202
+
203
+ // it will be automatically made async
204
+ // even it iterator "returns" in the same event loop
205
+ cb(null, item * 2);
206
+ }
207
+ ```
208
+
209
+ More examples could be found in [test/test-serial-object.js](test/test-serial-object.js).
210
+
211
+ _Note: Since _object_ is an _unordered_ collection of properties,
212
+ it may produce unexpected results with sequential iterations.
213
+ Whenever order of the jobs' execution is important please use `serialOrdered` method._
214
+
215
+ ### Ordered Serial Iterations
216
+
217
+ TBD
218
+
219
+ For example [compare-property](compare-property) package.
220
+
221
+ ### Streaming interface
222
+
223
+ TBD
224
+
225
+ ## Want to Know More?
226
+
227
+ More examples can be found in [test folder](test/).
228
+
229
+ Or open an [issue](https://github.com/alexindigo/asynckit/issues) with questions and/or suggestions.
230
+
231
+ ## License
232
+
233
+ AsyncKit is licensed under the MIT license.