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.
- package/LICENSE +14 -0
- package/README.md +35 -0
- package/node_modules/adm-zip/LICENSE +21 -0
- package/node_modules/adm-zip/README.md +65 -0
- package/node_modules/adm-zip/adm-zip.js +783 -0
- package/node_modules/adm-zip/headers/entryHeader.js +338 -0
- package/node_modules/adm-zip/headers/index.js +2 -0
- package/node_modules/adm-zip/headers/mainHeader.js +129 -0
- package/node_modules/adm-zip/methods/deflater.js +33 -0
- package/node_modules/adm-zip/methods/index.js +3 -0
- package/node_modules/adm-zip/methods/inflater.js +31 -0
- package/node_modules/adm-zip/methods/zipcrypto.js +170 -0
- package/node_modules/adm-zip/package.json +77 -0
- package/node_modules/adm-zip/util/constants.js +142 -0
- package/node_modules/adm-zip/util/errors.js +35 -0
- package/node_modules/adm-zip/util/fattr.js +79 -0
- package/node_modules/adm-zip/util/fileSystem.js +11 -0
- package/node_modules/adm-zip/util/index.js +4 -0
- package/node_modules/adm-zip/util/utils.js +246 -0
- package/node_modules/adm-zip/zipEntry.js +333 -0
- package/node_modules/adm-zip/zipFile.js +384 -0
- package/node_modules/asynckit/LICENSE +21 -0
- package/node_modules/asynckit/README.md +233 -0
- package/node_modules/asynckit/bench.js +76 -0
- package/node_modules/asynckit/index.js +6 -0
- package/node_modules/asynckit/lib/abort.js +29 -0
- package/node_modules/asynckit/lib/async.js +34 -0
- package/node_modules/asynckit/lib/defer.js +26 -0
- package/node_modules/asynckit/lib/iterate.js +75 -0
- package/node_modules/asynckit/lib/readable_asynckit.js +91 -0
- package/node_modules/asynckit/lib/readable_parallel.js +25 -0
- package/node_modules/asynckit/lib/readable_serial.js +25 -0
- package/node_modules/asynckit/lib/readable_serial_ordered.js +29 -0
- package/node_modules/asynckit/lib/state.js +37 -0
- package/node_modules/asynckit/lib/streamify.js +141 -0
- package/node_modules/asynckit/lib/terminator.js +29 -0
- package/node_modules/asynckit/package.json +91 -0
- package/node_modules/asynckit/parallel.js +43 -0
- package/node_modules/asynckit/serial.js +17 -0
- package/node_modules/asynckit/serialOrdered.js +75 -0
- package/node_modules/asynckit/stream.js +21 -0
- package/node_modules/axios/CHANGELOG.md +836 -0
- package/node_modules/axios/LICENSE +19 -0
- package/node_modules/axios/README.md +892 -0
- package/node_modules/axios/SECURITY.md +5 -0
- package/node_modules/axios/UPGRADE_GUIDE.md +162 -0
- package/node_modules/axios/dist/axios.js +2275 -0
- package/node_modules/axios/dist/axios.map +1 -0
- package/node_modules/axios/dist/axios.min.js +2 -0
- package/node_modules/axios/dist/axios.min.map +1 -0
- package/node_modules/axios/index.d.ts +206 -0
- package/node_modules/axios/index.js +1 -0
- package/node_modules/axios/lib/adapters/README.md +37 -0
- package/node_modules/axios/lib/adapters/http.js +363 -0
- package/node_modules/axios/lib/adapters/xhr.js +212 -0
- package/node_modules/axios/lib/axios.js +57 -0
- package/node_modules/axios/lib/cancel/Cancel.js +19 -0
- package/node_modules/axios/lib/cancel/CancelToken.js +119 -0
- package/node_modules/axios/lib/cancel/isCancel.js +5 -0
- package/node_modules/axios/lib/core/Axios.js +148 -0
- package/node_modules/axios/lib/core/InterceptorManager.js +54 -0
- package/node_modules/axios/lib/core/README.md +8 -0
- package/node_modules/axios/lib/core/buildFullPath.js +20 -0
- package/node_modules/axios/lib/core/createError.js +18 -0
- package/node_modules/axios/lib/core/dispatchRequest.js +87 -0
- package/node_modules/axios/lib/core/enhanceError.js +43 -0
- package/node_modules/axios/lib/core/mergeConfig.js +99 -0
- package/node_modules/axios/lib/core/settle.js +25 -0
- package/node_modules/axios/lib/core/transformData.js +22 -0
- package/node_modules/axios/lib/defaults.js +134 -0
- package/node_modules/axios/lib/env/README.md +3 -0
- package/node_modules/axios/lib/env/data.js +3 -0
- package/node_modules/axios/lib/helpers/README.md +7 -0
- package/node_modules/axios/lib/helpers/bind.js +11 -0
- package/node_modules/axios/lib/helpers/buildURL.js +70 -0
- package/node_modules/axios/lib/helpers/combineURLs.js +14 -0
- package/node_modules/axios/lib/helpers/cookies.js +53 -0
- package/node_modules/axios/lib/helpers/deprecatedMethod.js +24 -0
- package/node_modules/axios/lib/helpers/isAbsoluteURL.js +14 -0
- package/node_modules/axios/lib/helpers/isAxiosError.js +11 -0
- package/node_modules/axios/lib/helpers/isURLSameOrigin.js +68 -0
- package/node_modules/axios/lib/helpers/normalizeHeaderName.js +12 -0
- package/node_modules/axios/lib/helpers/parseHeaders.js +53 -0
- package/node_modules/axios/lib/helpers/spread.js +27 -0
- package/node_modules/axios/lib/helpers/validator.js +82 -0
- package/node_modules/axios/lib/utils.js +349 -0
- package/node_modules/axios/package.json +113 -0
- package/node_modules/axios/tsconfig.json +14 -0
- package/node_modules/axios/tslint.json +6 -0
- package/node_modules/combined-stream/License +19 -0
- package/node_modules/combined-stream/Readme.md +138 -0
- package/node_modules/combined-stream/lib/combined_stream.js +208 -0
- package/node_modules/combined-stream/package.json +57 -0
- package/node_modules/combined-stream/yarn.lock +17 -0
- package/node_modules/delayed-stream/.npmignore +1 -0
- package/node_modules/delayed-stream/License +19 -0
- package/node_modules/delayed-stream/Makefile +7 -0
- package/node_modules/delayed-stream/Readme.md +141 -0
- package/node_modules/delayed-stream/lib/delayed_stream.js +107 -0
- package/node_modules/delayed-stream/package.json +62 -0
- package/node_modules/follow-redirects/LICENSE +18 -0
- package/node_modules/follow-redirects/README.md +148 -0
- package/node_modules/follow-redirects/debug.js +15 -0
- package/node_modules/follow-redirects/http.js +1 -0
- package/node_modules/follow-redirects/https.js +1 -0
- package/node_modules/follow-redirects/index.js +569 -0
- package/node_modules/follow-redirects/package.json +95 -0
- package/node_modules/form-data/License +19 -0
- package/node_modules/form-data/README.md.bak +358 -0
- package/node_modules/form-data/Readme.md +358 -0
- package/node_modules/form-data/index.d.ts +62 -0
- package/node_modules/form-data/lib/browser.js +2 -0
- package/node_modules/form-data/lib/form_data.js +501 -0
- package/node_modules/form-data/lib/populate.js +10 -0
- package/node_modules/form-data/package.json +101 -0
- package/node_modules/mime-db/HISTORY.md +499 -0
- package/node_modules/mime-db/LICENSE +22 -0
- package/node_modules/mime-db/README.md +100 -0
- package/node_modules/mime-db/db.json +8471 -0
- package/node_modules/mime-db/index.js +11 -0
- package/node_modules/mime-db/package.json +102 -0
- package/node_modules/mime-types/HISTORY.md +388 -0
- package/node_modules/mime-types/LICENSE +23 -0
- package/node_modules/mime-types/README.md +113 -0
- package/node_modules/mime-types/index.js +188 -0
- package/node_modules/mime-types/package.json +87 -0
- package/node_modules/uuid/CHANGELOG.md +229 -0
- package/node_modules/uuid/CONTRIBUTING.md +18 -0
- package/node_modules/uuid/LICENSE.md +9 -0
- package/node_modules/uuid/README.md +505 -0
- package/node_modules/uuid/dist/bin/uuid +2 -0
- package/node_modules/uuid/dist/esm-browser/index.js +9 -0
- package/node_modules/uuid/dist/esm-browser/md5.js +215 -0
- package/node_modules/uuid/dist/esm-browser/nil.js +1 -0
- package/node_modules/uuid/dist/esm-browser/parse.js +35 -0
- package/node_modules/uuid/dist/esm-browser/regex.js +1 -0
- package/node_modules/uuid/dist/esm-browser/rng.js +19 -0
- package/node_modules/uuid/dist/esm-browser/sha1.js +96 -0
- package/node_modules/uuid/dist/esm-browser/stringify.js +30 -0
- package/node_modules/uuid/dist/esm-browser/v1.js +95 -0
- package/node_modules/uuid/dist/esm-browser/v3.js +4 -0
- package/node_modules/uuid/dist/esm-browser/v35.js +64 -0
- package/node_modules/uuid/dist/esm-browser/v4.js +24 -0
- package/node_modules/uuid/dist/esm-browser/v5.js +4 -0
- package/node_modules/uuid/dist/esm-browser/validate.js +7 -0
- package/node_modules/uuid/dist/esm-browser/version.js +11 -0
- package/node_modules/uuid/dist/esm-node/index.js +9 -0
- package/node_modules/uuid/dist/esm-node/md5.js +13 -0
- package/node_modules/uuid/dist/esm-node/nil.js +1 -0
- package/node_modules/uuid/dist/esm-node/parse.js +35 -0
- package/node_modules/uuid/dist/esm-node/regex.js +1 -0
- package/node_modules/uuid/dist/esm-node/rng.js +12 -0
- package/node_modules/uuid/dist/esm-node/sha1.js +13 -0
- package/node_modules/uuid/dist/esm-node/stringify.js +29 -0
- package/node_modules/uuid/dist/esm-node/v1.js +95 -0
- package/node_modules/uuid/dist/esm-node/v3.js +4 -0
- package/node_modules/uuid/dist/esm-node/v35.js +64 -0
- package/node_modules/uuid/dist/esm-node/v4.js +24 -0
- package/node_modules/uuid/dist/esm-node/v5.js +4 -0
- package/node_modules/uuid/dist/esm-node/validate.js +7 -0
- package/node_modules/uuid/dist/esm-node/version.js +11 -0
- package/node_modules/uuid/dist/index.js +79 -0
- package/node_modules/uuid/dist/md5-browser.js +223 -0
- package/node_modules/uuid/dist/md5.js +23 -0
- package/node_modules/uuid/dist/nil.js +8 -0
- package/node_modules/uuid/dist/parse.js +45 -0
- package/node_modules/uuid/dist/regex.js +8 -0
- package/node_modules/uuid/dist/rng-browser.js +26 -0
- package/node_modules/uuid/dist/rng.js +24 -0
- package/node_modules/uuid/dist/sha1-browser.js +104 -0
- package/node_modules/uuid/dist/sha1.js +23 -0
- package/node_modules/uuid/dist/stringify.js +39 -0
- package/node_modules/uuid/dist/umd/uuid.min.js +1 -0
- package/node_modules/uuid/dist/umd/uuidNIL.min.js +1 -0
- package/node_modules/uuid/dist/umd/uuidParse.min.js +1 -0
- package/node_modules/uuid/dist/umd/uuidStringify.min.js +1 -0
- package/node_modules/uuid/dist/umd/uuidValidate.min.js +1 -0
- package/node_modules/uuid/dist/umd/uuidVersion.min.js +1 -0
- package/node_modules/uuid/dist/umd/uuidv1.min.js +1 -0
- package/node_modules/uuid/dist/umd/uuidv3.min.js +1 -0
- package/node_modules/uuid/dist/umd/uuidv4.min.js +1 -0
- package/node_modules/uuid/dist/umd/uuidv5.min.js +1 -0
- package/node_modules/uuid/dist/uuid-bin.js +85 -0
- package/node_modules/uuid/dist/v1.js +107 -0
- package/node_modules/uuid/dist/v3.js +16 -0
- package/node_modules/uuid/dist/v35.js +78 -0
- package/node_modules/uuid/dist/v4.js +37 -0
- package/node_modules/uuid/dist/v5.js +16 -0
- package/node_modules/uuid/dist/validate.js +17 -0
- package/node_modules/uuid/dist/version.js +21 -0
- package/node_modules/uuid/package.json +164 -0
- package/node_modules/uuid/wrapper.mjs +10 -0
- package/package.json +32 -0
- package/tak-registration.html +111 -0
- package/tak-registration.js +169 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
const fsystem = require("./fileSystem").require();
|
|
2
|
+
const pth = require("path");
|
|
3
|
+
const Constants = require("./constants");
|
|
4
|
+
const isWin = typeof process === "object" && "win32" === process.platform;
|
|
5
|
+
|
|
6
|
+
const is_Obj = (obj) => obj && typeof obj === "object";
|
|
7
|
+
|
|
8
|
+
// generate CRC32 lookup table
|
|
9
|
+
const crcTable = new Uint32Array(256).map((t, c) => {
|
|
10
|
+
for (let k = 0; k < 8; k++) {
|
|
11
|
+
if ((c & 1) !== 0) {
|
|
12
|
+
c = 0xedb88320 ^ (c >>> 1);
|
|
13
|
+
} else {
|
|
14
|
+
c >>>= 1;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return c >>> 0;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// UTILS functions
|
|
21
|
+
|
|
22
|
+
function Utils(opts) {
|
|
23
|
+
this.sep = pth.sep;
|
|
24
|
+
this.fs = fsystem;
|
|
25
|
+
|
|
26
|
+
if (is_Obj(opts)) {
|
|
27
|
+
// custom filesystem
|
|
28
|
+
if (is_Obj(opts.fs) && typeof opts.fs.statSync === "function") {
|
|
29
|
+
this.fs = opts.fs;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = Utils;
|
|
35
|
+
|
|
36
|
+
// INSTANCED functions
|
|
37
|
+
|
|
38
|
+
Utils.prototype.makeDir = function (/*String*/ folder) {
|
|
39
|
+
const self = this;
|
|
40
|
+
|
|
41
|
+
// Sync - make directories tree
|
|
42
|
+
function mkdirSync(/*String*/ fpath) {
|
|
43
|
+
let resolvedPath = fpath.split(self.sep)[0];
|
|
44
|
+
fpath.split(self.sep).forEach(function (name) {
|
|
45
|
+
if (!name || name.substr(-1, 1) === ":") return;
|
|
46
|
+
resolvedPath += self.sep + name;
|
|
47
|
+
var stat;
|
|
48
|
+
try {
|
|
49
|
+
stat = self.fs.statSync(resolvedPath);
|
|
50
|
+
} catch (e) {
|
|
51
|
+
self.fs.mkdirSync(resolvedPath);
|
|
52
|
+
}
|
|
53
|
+
if (stat && stat.isFile()) throw Errors.FILE_IN_THE_WAY.replace("%s", resolvedPath);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
mkdirSync(folder);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
Utils.prototype.writeFileTo = function (/*String*/ path, /*Buffer*/ content, /*Boolean*/ overwrite, /*Number*/ attr) {
|
|
61
|
+
const self = this;
|
|
62
|
+
if (self.fs.existsSync(path)) {
|
|
63
|
+
if (!overwrite) return false; // cannot overwrite
|
|
64
|
+
|
|
65
|
+
var stat = self.fs.statSync(path);
|
|
66
|
+
if (stat.isDirectory()) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
var folder = pth.dirname(path);
|
|
71
|
+
if (!self.fs.existsSync(folder)) {
|
|
72
|
+
self.makeDir(folder);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
var fd;
|
|
76
|
+
try {
|
|
77
|
+
fd = self.fs.openSync(path, "w", 438); // 0666
|
|
78
|
+
} catch (e) {
|
|
79
|
+
self.fs.chmodSync(path, 438);
|
|
80
|
+
fd = self.fs.openSync(path, "w", 438);
|
|
81
|
+
}
|
|
82
|
+
if (fd) {
|
|
83
|
+
try {
|
|
84
|
+
self.fs.writeSync(fd, content, 0, content.length, 0);
|
|
85
|
+
} finally {
|
|
86
|
+
self.fs.closeSync(fd);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
self.fs.chmodSync(path, attr || 438);
|
|
90
|
+
return true;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
Utils.prototype.writeFileToAsync = function (/*String*/ path, /*Buffer*/ content, /*Boolean*/ overwrite, /*Number*/ attr, /*Function*/ callback) {
|
|
94
|
+
if (typeof attr === "function") {
|
|
95
|
+
callback = attr;
|
|
96
|
+
attr = undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const self = this;
|
|
100
|
+
|
|
101
|
+
self.fs.exists(path, function (exist) {
|
|
102
|
+
if (exist && !overwrite) return callback(false);
|
|
103
|
+
|
|
104
|
+
self.fs.stat(path, function (err, stat) {
|
|
105
|
+
if (exist && stat.isDirectory()) {
|
|
106
|
+
return callback(false);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var folder = pth.dirname(path);
|
|
110
|
+
self.fs.exists(folder, function (exists) {
|
|
111
|
+
if (!exists) self.makeDir(folder);
|
|
112
|
+
|
|
113
|
+
self.fs.open(path, "w", 438, function (err, fd) {
|
|
114
|
+
if (err) {
|
|
115
|
+
self.fs.chmod(path, 438, function () {
|
|
116
|
+
self.fs.open(path, "w", 438, function (err, fd) {
|
|
117
|
+
self.fs.write(fd, content, 0, content.length, 0, function () {
|
|
118
|
+
self.fs.close(fd, function () {
|
|
119
|
+
self.fs.chmod(path, attr || 438, function () {
|
|
120
|
+
callback(true);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
} else if (fd) {
|
|
127
|
+
self.fs.write(fd, content, 0, content.length, 0, function () {
|
|
128
|
+
self.fs.close(fd, function () {
|
|
129
|
+
self.fs.chmod(path, attr || 438, function () {
|
|
130
|
+
callback(true);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
} else {
|
|
135
|
+
self.fs.chmod(path, attr || 438, function () {
|
|
136
|
+
callback(true);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
Utils.prototype.findFiles = function (/*String*/ path) {
|
|
146
|
+
const self = this;
|
|
147
|
+
|
|
148
|
+
function findSync(/*String*/ dir, /*RegExp*/ pattern, /*Boolean*/ recursive) {
|
|
149
|
+
if (typeof pattern === "boolean") {
|
|
150
|
+
recursive = pattern;
|
|
151
|
+
pattern = undefined;
|
|
152
|
+
}
|
|
153
|
+
let files = [];
|
|
154
|
+
self.fs.readdirSync(dir).forEach(function (file) {
|
|
155
|
+
var path = pth.join(dir, file);
|
|
156
|
+
|
|
157
|
+
if (self.fs.statSync(path).isDirectory() && recursive) files = files.concat(findSync(path, pattern, recursive));
|
|
158
|
+
|
|
159
|
+
if (!pattern || pattern.test(path)) {
|
|
160
|
+
files.push(pth.normalize(path) + (self.fs.statSync(path).isDirectory() ? self.sep : ""));
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
return files;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return findSync(path, undefined, true);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
Utils.prototype.getAttributes = function () {};
|
|
170
|
+
|
|
171
|
+
Utils.prototype.setAttributes = function () {};
|
|
172
|
+
|
|
173
|
+
// STATIC functions
|
|
174
|
+
|
|
175
|
+
// crc32 single update (it is part of crc32)
|
|
176
|
+
Utils.crc32update = function (crc, byte) {
|
|
177
|
+
return crcTable[(crc ^ byte) & 0xff] ^ (crc >>> 8);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
Utils.crc32 = function (buf) {
|
|
181
|
+
if (typeof buf === "string") {
|
|
182
|
+
buf = Buffer.from(buf, "utf8");
|
|
183
|
+
}
|
|
184
|
+
// Generate crcTable
|
|
185
|
+
if (!crcTable.length) genCRCTable();
|
|
186
|
+
|
|
187
|
+
let len = buf.length;
|
|
188
|
+
let crc = ~0;
|
|
189
|
+
for (let off = 0; off < len; ) crc = Utils.crc32update(crc, buf[off++]);
|
|
190
|
+
// xor and cast as uint32 number
|
|
191
|
+
return ~crc >>> 0;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
Utils.methodToString = function (/*Number*/ method) {
|
|
195
|
+
switch (method) {
|
|
196
|
+
case Constants.STORED:
|
|
197
|
+
return "STORED (" + method + ")";
|
|
198
|
+
case Constants.DEFLATED:
|
|
199
|
+
return "DEFLATED (" + method + ")";
|
|
200
|
+
default:
|
|
201
|
+
return "UNSUPPORTED (" + method + ")";
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// removes ".." style path elements
|
|
206
|
+
Utils.canonical = function (/*string*/ path) {
|
|
207
|
+
if (!path) return "";
|
|
208
|
+
// trick normalize think path is absolute
|
|
209
|
+
var safeSuffix = pth.posix.normalize("/" + path.split("\\").join("/"));
|
|
210
|
+
return pth.join(".", safeSuffix);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// make abolute paths taking prefix as root folder
|
|
214
|
+
Utils.sanitize = function (/*string*/ prefix, /*string*/ name) {
|
|
215
|
+
prefix = pth.resolve(pth.normalize(prefix));
|
|
216
|
+
var parts = name.split("/");
|
|
217
|
+
for (var i = 0, l = parts.length; i < l; i++) {
|
|
218
|
+
var path = pth.normalize(pth.join(prefix, parts.slice(i, l).join(pth.sep)));
|
|
219
|
+
if (path.indexOf(prefix) === 0) {
|
|
220
|
+
return path;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return pth.normalize(pth.join(prefix, pth.basename(name)));
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// converts buffer, Uint8Array, string types to buffer
|
|
227
|
+
Utils.toBuffer = function toBuffer(/*buffer, Uint8Array, string*/ input) {
|
|
228
|
+
if (Buffer.isBuffer(input)) {
|
|
229
|
+
return input;
|
|
230
|
+
} else if (input instanceof Uint8Array) {
|
|
231
|
+
return Buffer.from(input);
|
|
232
|
+
} else {
|
|
233
|
+
// expect string all other values are invalid and return empty buffer
|
|
234
|
+
return typeof input === "string" ? Buffer.from(input, "utf8") : Buffer.alloc(0);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
Utils.readBigUInt64LE = function (/*Buffer*/ buffer, /*int*/ index) {
|
|
239
|
+
var slice = Buffer.from(buffer.slice(index, index + 8));
|
|
240
|
+
slice.swap64();
|
|
241
|
+
|
|
242
|
+
return parseInt(`0x${slice.toString("hex")}`);
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
Utils.isWin = isWin; // Do we have windows system
|
|
246
|
+
Utils.crcTable = crcTable;
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
var Utils = require("./util"),
|
|
2
|
+
Headers = require("./headers"),
|
|
3
|
+
Constants = Utils.Constants,
|
|
4
|
+
Methods = require("./methods");
|
|
5
|
+
|
|
6
|
+
module.exports = function (/*Buffer*/ input) {
|
|
7
|
+
var _entryHeader = new Headers.EntryHeader(),
|
|
8
|
+
_entryName = Buffer.alloc(0),
|
|
9
|
+
_comment = Buffer.alloc(0),
|
|
10
|
+
_isDirectory = false,
|
|
11
|
+
uncompressedData = null,
|
|
12
|
+
_extra = Buffer.alloc(0);
|
|
13
|
+
|
|
14
|
+
function getCompressedDataFromZip() {
|
|
15
|
+
if (!input || !Buffer.isBuffer(input)) {
|
|
16
|
+
return Buffer.alloc(0);
|
|
17
|
+
}
|
|
18
|
+
_entryHeader.loadDataHeaderFromBinary(input);
|
|
19
|
+
return input.slice(_entryHeader.realDataOffset, _entryHeader.realDataOffset + _entryHeader.compressedSize);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function crc32OK(data) {
|
|
23
|
+
// if bit 3 (0x08) of the general-purpose flags field is set, then the CRC-32 and file sizes are not known when the header is written
|
|
24
|
+
if ((_entryHeader.flags & 0x8) !== 0x8) {
|
|
25
|
+
if (Utils.crc32(data) !== _entryHeader.dataHeader.crc) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
// @TODO: load and check data descriptor header
|
|
30
|
+
// The fields in the local header are filled with zero, and the CRC-32 and size are appended in a 12-byte structure
|
|
31
|
+
// (optionally preceded by a 4-byte signature) immediately after the compressed data:
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function decompress(/*Boolean*/ async, /*Function*/ callback, /*String, Buffer*/ pass) {
|
|
37
|
+
if (typeof callback === "undefined" && typeof async === "string") {
|
|
38
|
+
pass = async;
|
|
39
|
+
async = void 0;
|
|
40
|
+
}
|
|
41
|
+
if (_isDirectory) {
|
|
42
|
+
if (async && callback) {
|
|
43
|
+
callback(Buffer.alloc(0), Utils.Errors.DIRECTORY_CONTENT_ERROR); //si added error.
|
|
44
|
+
}
|
|
45
|
+
return Buffer.alloc(0);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
var compressedData = getCompressedDataFromZip();
|
|
49
|
+
|
|
50
|
+
if (compressedData.length === 0) {
|
|
51
|
+
// File is empty, nothing to decompress.
|
|
52
|
+
if (async && callback) callback(compressedData);
|
|
53
|
+
return compressedData;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (_entryHeader.encripted) {
|
|
57
|
+
if ("string" !== typeof pass && !Buffer.isBuffer(pass)) {
|
|
58
|
+
throw new Error("ADM-ZIP: Incompatible password parameter");
|
|
59
|
+
}
|
|
60
|
+
compressedData = Methods.ZipCrypto.decrypt(compressedData, _entryHeader, pass);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
var data = Buffer.alloc(_entryHeader.size);
|
|
64
|
+
|
|
65
|
+
switch (_entryHeader.method) {
|
|
66
|
+
case Utils.Constants.STORED:
|
|
67
|
+
compressedData.copy(data);
|
|
68
|
+
if (!crc32OK(data)) {
|
|
69
|
+
if (async && callback) callback(data, Utils.Errors.BAD_CRC); //si added error
|
|
70
|
+
throw new Error(Utils.Errors.BAD_CRC);
|
|
71
|
+
} else {
|
|
72
|
+
//si added otherwise did not seem to return data.
|
|
73
|
+
if (async && callback) callback(data);
|
|
74
|
+
return data;
|
|
75
|
+
}
|
|
76
|
+
case Utils.Constants.DEFLATED:
|
|
77
|
+
var inflater = new Methods.Inflater(compressedData);
|
|
78
|
+
if (!async) {
|
|
79
|
+
const result = inflater.inflate(data);
|
|
80
|
+
result.copy(data, 0);
|
|
81
|
+
if (!crc32OK(data)) {
|
|
82
|
+
throw new Error(Utils.Errors.BAD_CRC + " " + _entryName.toString());
|
|
83
|
+
}
|
|
84
|
+
return data;
|
|
85
|
+
} else {
|
|
86
|
+
inflater.inflateAsync(function (result) {
|
|
87
|
+
result.copy(result, 0);
|
|
88
|
+
if (callback) {
|
|
89
|
+
if (!crc32OK(result)) {
|
|
90
|
+
callback(result, Utils.Errors.BAD_CRC); //si added error
|
|
91
|
+
} else {
|
|
92
|
+
callback(result);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
default:
|
|
99
|
+
if (async && callback) callback(Buffer.alloc(0), Utils.Errors.UNKNOWN_METHOD);
|
|
100
|
+
throw new Error(Utils.Errors.UNKNOWN_METHOD);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function compress(/*Boolean*/ async, /*Function*/ callback) {
|
|
105
|
+
if ((!uncompressedData || !uncompressedData.length) && Buffer.isBuffer(input)) {
|
|
106
|
+
// no data set or the data wasn't changed to require recompression
|
|
107
|
+
if (async && callback) callback(getCompressedDataFromZip());
|
|
108
|
+
return getCompressedDataFromZip();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (uncompressedData.length && !_isDirectory) {
|
|
112
|
+
var compressedData;
|
|
113
|
+
// Local file header
|
|
114
|
+
switch (_entryHeader.method) {
|
|
115
|
+
case Utils.Constants.STORED:
|
|
116
|
+
_entryHeader.compressedSize = _entryHeader.size;
|
|
117
|
+
|
|
118
|
+
compressedData = Buffer.alloc(uncompressedData.length);
|
|
119
|
+
uncompressedData.copy(compressedData);
|
|
120
|
+
|
|
121
|
+
if (async && callback) callback(compressedData);
|
|
122
|
+
return compressedData;
|
|
123
|
+
default:
|
|
124
|
+
case Utils.Constants.DEFLATED:
|
|
125
|
+
var deflater = new Methods.Deflater(uncompressedData);
|
|
126
|
+
if (!async) {
|
|
127
|
+
var deflated = deflater.deflate();
|
|
128
|
+
_entryHeader.compressedSize = deflated.length;
|
|
129
|
+
return deflated;
|
|
130
|
+
} else {
|
|
131
|
+
deflater.deflateAsync(function (data) {
|
|
132
|
+
compressedData = Buffer.alloc(data.length);
|
|
133
|
+
_entryHeader.compressedSize = data.length;
|
|
134
|
+
data.copy(compressedData);
|
|
135
|
+
callback && callback(compressedData);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
deflater = null;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
} else if (async && callback) {
|
|
142
|
+
callback(Buffer.alloc(0));
|
|
143
|
+
} else {
|
|
144
|
+
return Buffer.alloc(0);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function readUInt64LE(buffer, offset) {
|
|
149
|
+
return (buffer.readUInt32LE(offset + 4) << 4) + buffer.readUInt32LE(offset);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function parseExtra(data) {
|
|
153
|
+
var offset = 0;
|
|
154
|
+
var signature, size, part;
|
|
155
|
+
while (offset < data.length) {
|
|
156
|
+
signature = data.readUInt16LE(offset);
|
|
157
|
+
offset += 2;
|
|
158
|
+
size = data.readUInt16LE(offset);
|
|
159
|
+
offset += 2;
|
|
160
|
+
part = data.slice(offset, offset + size);
|
|
161
|
+
offset += size;
|
|
162
|
+
if (Constants.ID_ZIP64 === signature) {
|
|
163
|
+
parseZip64ExtendedInformation(part);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
//Override header field values with values from the ZIP64 extra field
|
|
169
|
+
function parseZip64ExtendedInformation(data) {
|
|
170
|
+
var size, compressedSize, offset, diskNumStart;
|
|
171
|
+
|
|
172
|
+
if (data.length >= Constants.EF_ZIP64_SCOMP) {
|
|
173
|
+
size = readUInt64LE(data, Constants.EF_ZIP64_SUNCOMP);
|
|
174
|
+
if (_entryHeader.size === Constants.EF_ZIP64_OR_32) {
|
|
175
|
+
_entryHeader.size = size;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (data.length >= Constants.EF_ZIP64_RHO) {
|
|
179
|
+
compressedSize = readUInt64LE(data, Constants.EF_ZIP64_SCOMP);
|
|
180
|
+
if (_entryHeader.compressedSize === Constants.EF_ZIP64_OR_32) {
|
|
181
|
+
_entryHeader.compressedSize = compressedSize;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (data.length >= Constants.EF_ZIP64_DSN) {
|
|
185
|
+
offset = readUInt64LE(data, Constants.EF_ZIP64_RHO);
|
|
186
|
+
if (_entryHeader.offset === Constants.EF_ZIP64_OR_32) {
|
|
187
|
+
_entryHeader.offset = offset;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (data.length >= Constants.EF_ZIP64_DSN + 4) {
|
|
191
|
+
diskNumStart = data.readUInt32LE(Constants.EF_ZIP64_DSN);
|
|
192
|
+
if (_entryHeader.diskNumStart === Constants.EF_ZIP64_OR_16) {
|
|
193
|
+
_entryHeader.diskNumStart = diskNumStart;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
get entryName() {
|
|
200
|
+
return _entryName.toString();
|
|
201
|
+
},
|
|
202
|
+
get rawEntryName() {
|
|
203
|
+
return _entryName;
|
|
204
|
+
},
|
|
205
|
+
set entryName(val) {
|
|
206
|
+
_entryName = Utils.toBuffer(val);
|
|
207
|
+
var lastChar = _entryName[_entryName.length - 1];
|
|
208
|
+
_isDirectory = lastChar === 47 || lastChar === 92;
|
|
209
|
+
_entryHeader.fileNameLength = _entryName.length;
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
get extra() {
|
|
213
|
+
return _extra;
|
|
214
|
+
},
|
|
215
|
+
set extra(val) {
|
|
216
|
+
_extra = val;
|
|
217
|
+
_entryHeader.extraLength = val.length;
|
|
218
|
+
parseExtra(val);
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
get comment() {
|
|
222
|
+
return _comment.toString();
|
|
223
|
+
},
|
|
224
|
+
set comment(val) {
|
|
225
|
+
_comment = Utils.toBuffer(val);
|
|
226
|
+
_entryHeader.commentLength = _comment.length;
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
get name() {
|
|
230
|
+
var n = _entryName.toString();
|
|
231
|
+
return _isDirectory
|
|
232
|
+
? n
|
|
233
|
+
.substr(n.length - 1)
|
|
234
|
+
.split("/")
|
|
235
|
+
.pop()
|
|
236
|
+
: n.split("/").pop();
|
|
237
|
+
},
|
|
238
|
+
get isDirectory() {
|
|
239
|
+
return _isDirectory;
|
|
240
|
+
},
|
|
241
|
+
|
|
242
|
+
getCompressedData: function () {
|
|
243
|
+
return compress(false, null);
|
|
244
|
+
},
|
|
245
|
+
|
|
246
|
+
getCompressedDataAsync: function (/*Function*/ callback) {
|
|
247
|
+
compress(true, callback);
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
setData: function (value) {
|
|
251
|
+
uncompressedData = Utils.toBuffer(value);
|
|
252
|
+
if (!_isDirectory && uncompressedData.length) {
|
|
253
|
+
_entryHeader.size = uncompressedData.length;
|
|
254
|
+
_entryHeader.method = Utils.Constants.DEFLATED;
|
|
255
|
+
_entryHeader.crc = Utils.crc32(value);
|
|
256
|
+
_entryHeader.changed = true;
|
|
257
|
+
} else {
|
|
258
|
+
// folders and blank files should be stored
|
|
259
|
+
_entryHeader.method = Utils.Constants.STORED;
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
getData: function (pass) {
|
|
264
|
+
if (_entryHeader.changed) {
|
|
265
|
+
return uncompressedData;
|
|
266
|
+
} else {
|
|
267
|
+
return decompress(false, null, pass);
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
getDataAsync: function (/*Function*/ callback, pass) {
|
|
272
|
+
if (_entryHeader.changed) {
|
|
273
|
+
callback(uncompressedData);
|
|
274
|
+
} else {
|
|
275
|
+
decompress(true, callback, pass);
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
|
|
279
|
+
set attr(attr) {
|
|
280
|
+
_entryHeader.attr = attr;
|
|
281
|
+
},
|
|
282
|
+
get attr() {
|
|
283
|
+
return _entryHeader.attr;
|
|
284
|
+
},
|
|
285
|
+
|
|
286
|
+
set header(/*Buffer*/ data) {
|
|
287
|
+
_entryHeader.loadFromBinary(data);
|
|
288
|
+
},
|
|
289
|
+
|
|
290
|
+
get header() {
|
|
291
|
+
return _entryHeader;
|
|
292
|
+
},
|
|
293
|
+
|
|
294
|
+
packHeader: function () {
|
|
295
|
+
// 1. create header (buffer)
|
|
296
|
+
var header = _entryHeader.entryHeaderToBinary();
|
|
297
|
+
var addpos = Utils.Constants.CENHDR;
|
|
298
|
+
// 2. add file name
|
|
299
|
+
_entryName.copy(header, addpos);
|
|
300
|
+
addpos += _entryName.length;
|
|
301
|
+
// 3. add extra data
|
|
302
|
+
if (_entryHeader.extraLength) {
|
|
303
|
+
_extra.copy(header, addpos);
|
|
304
|
+
addpos += _entryHeader.extraLength;
|
|
305
|
+
}
|
|
306
|
+
// 4. add file comment
|
|
307
|
+
if (_entryHeader.commentLength) {
|
|
308
|
+
_comment.copy(header, addpos);
|
|
309
|
+
}
|
|
310
|
+
return header;
|
|
311
|
+
},
|
|
312
|
+
|
|
313
|
+
toJSON: function () {
|
|
314
|
+
const bytes = function (nr) {
|
|
315
|
+
return "<" + ((nr && nr.length + " bytes buffer") || "null") + ">";
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
return {
|
|
319
|
+
entryName: this.entryName,
|
|
320
|
+
name: this.name,
|
|
321
|
+
comment: this.comment,
|
|
322
|
+
isDirectory: this.isDirectory,
|
|
323
|
+
header: _entryHeader.toJSON(),
|
|
324
|
+
compressedData: bytes(input),
|
|
325
|
+
data: bytes(uncompressedData)
|
|
326
|
+
};
|
|
327
|
+
},
|
|
328
|
+
|
|
329
|
+
toString: function () {
|
|
330
|
+
return JSON.stringify(this.toJSON(), null, "\t");
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
};
|