motion-master-client 0.0.406 → 0.0.408
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/package.json +2 -3
- package/src/api.js +159 -121
- package/src/api.js.map +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/index.js.map +1 -1
- package/src/lib/firmware-esi.d.ts +25 -0
- package/src/lib/firmware-esi.js +48 -0
- package/src/lib/firmware-esi.js.map +1 -0
- package/src/lib/motion-master-req-res-client.d.ts +39 -0
- package/src/lib/motion-master-req-res-client.js +65 -0
- package/src/lib/motion-master-req-res-client.js.map +1 -1
- package/src/lib/unpack-bundle.d.ts +21 -3
- package/src/lib/unpack-bundle.js +115 -28
- package/src/lib/unpack-bundle.js.map +1 -1
|
@@ -1,12 +1,30 @@
|
|
|
1
|
+
export interface TarItem {
|
|
2
|
+
name: string;
|
|
3
|
+
buffer: ArrayBuffer;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Parses the content of a (decompressed) TAR archive and returns its regular file entries.
|
|
7
|
+
*
|
|
8
|
+
* This is a minimal, dependency-free reader that works in both the browser and Node.js. It handles long entry
|
|
9
|
+
* names from the USTAR `prefix` field, GNU long name (`L` type flag) entries, and PAX extended headers (`x` type
|
|
10
|
+
* flag), and skips directories and other non-regular entries.
|
|
11
|
+
*
|
|
12
|
+
* @param data - The decompressed TAR archive content.
|
|
13
|
+
* @returns The regular file entries with their name and content.
|
|
14
|
+
*/
|
|
15
|
+
export declare function readTarItems(data: Uint8Array): TarItem[];
|
|
1
16
|
/**
|
|
2
17
|
* Unpacks the .tar.gz (odbx format) file and returns the items.
|
|
3
18
|
*
|
|
19
|
+
* Works in both the browser and Node.js: decompression uses `fflate` and the TAR archive is read by
|
|
20
|
+
* {@link readTarItems}, so it does not depend on any browser-only API.
|
|
21
|
+
*
|
|
4
22
|
* @param data - The .tar.gz (odbx format) file.
|
|
5
23
|
* @returns - The items in the .tar.gz file.
|
|
6
24
|
*/
|
|
7
25
|
export declare function unpackBundle(data: Blob | ArrayBuffer): Promise<{
|
|
8
|
-
hasCache:
|
|
26
|
+
hasCache: boolean;
|
|
9
27
|
images: any;
|
|
10
|
-
items:
|
|
11
|
-
packages:
|
|
28
|
+
items: TarItem[];
|
|
29
|
+
packages: TarItem[];
|
|
12
30
|
}>;
|
package/src/lib/unpack-bundle.js
CHANGED
|
@@ -1,43 +1,130 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unpackBundle = void 0;
|
|
3
|
+
exports.unpackBundle = exports.readTarItems = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const fflate_1 = require("fflate");
|
|
6
|
+
/**
|
|
7
|
+
* Reads the `path` record from a PAX extended header block, which holds the real (long) name of the entry that
|
|
8
|
+
* follows it. PAX records are formatted as `"<length> <key>=<value>\n"`, concatenated. Returns `undefined` when
|
|
9
|
+
* there is no `path` record. Paths in our archives are ASCII, so byte and character lengths line up.
|
|
10
|
+
*/
|
|
11
|
+
function readPaxPath(content) {
|
|
12
|
+
const text = (0, fflate_1.strFromU8)(content);
|
|
13
|
+
let i = 0;
|
|
14
|
+
while (i < text.length) {
|
|
15
|
+
const space = text.indexOf(' ', i);
|
|
16
|
+
if (space < 0) {
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
const length = parseInt(text.slice(i, space), 10);
|
|
20
|
+
if (!Number.isFinite(length) || length <= 0) {
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
const record = text.slice(space + 1, i + length - 1); // exclude the trailing newline
|
|
24
|
+
const eq = record.indexOf('=');
|
|
25
|
+
if (eq >= 0 && record.slice(0, eq) === 'path') {
|
|
26
|
+
return record.slice(eq + 1);
|
|
27
|
+
}
|
|
28
|
+
i += length;
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Parses the content of a (decompressed) TAR archive and returns its regular file entries.
|
|
34
|
+
*
|
|
35
|
+
* This is a minimal, dependency-free reader that works in both the browser and Node.js. It handles long entry
|
|
36
|
+
* names from the USTAR `prefix` field, GNU long name (`L` type flag) entries, and PAX extended headers (`x` type
|
|
37
|
+
* flag), and skips directories and other non-regular entries.
|
|
38
|
+
*
|
|
39
|
+
* @param data - The decompressed TAR archive content.
|
|
40
|
+
* @returns The regular file entries with their name and content.
|
|
41
|
+
*/
|
|
42
|
+
function readTarItems(data) {
|
|
43
|
+
const items = [];
|
|
44
|
+
const readString = (offset, length) => (0, fflate_1.strFromU8)(data.subarray(offset, offset + length)).replace(/\0.*$/, '');
|
|
45
|
+
let offset = 0;
|
|
46
|
+
// Real name of the next entry, supplied by a preceding GNU 'L' or PAX 'x' header.
|
|
47
|
+
let overrideName = null;
|
|
48
|
+
while (offset + 512 <= data.length) {
|
|
49
|
+
// A zero-filled block marks the end of the archive.
|
|
50
|
+
let allZero = true;
|
|
51
|
+
for (let i = 0; i < 512; i++) {
|
|
52
|
+
if (data[offset + i] !== 0) {
|
|
53
|
+
allZero = false;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (allZero) {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
let name = readString(offset, 100);
|
|
61
|
+
const prefix = readString(offset + 345, 155);
|
|
62
|
+
if (prefix) {
|
|
63
|
+
name = `${prefix}/${name}`;
|
|
64
|
+
}
|
|
65
|
+
const size = parseInt(readString(offset + 124, 12).trim(), 8) || 0;
|
|
66
|
+
const typeFlag = String.fromCharCode(data[offset + 156]);
|
|
67
|
+
offset += 512;
|
|
68
|
+
const content = data.subarray(offset, offset + size);
|
|
69
|
+
if (typeFlag === 'L') {
|
|
70
|
+
// GNU long name: the entry content holds the real name of the following entry.
|
|
71
|
+
overrideName = (0, fflate_1.strFromU8)(content).replace(/\0.*$/, '');
|
|
72
|
+
}
|
|
73
|
+
else if (typeFlag === 'x') {
|
|
74
|
+
// PAX extended header: the real path of the following entry is in its `path` record.
|
|
75
|
+
const paxPath = readPaxPath(content);
|
|
76
|
+
if (paxPath) {
|
|
77
|
+
overrideName = paxPath;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else if (typeFlag === 'g') {
|
|
81
|
+
// PAX global extended header: not relevant to individual entry names.
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
if (overrideName) {
|
|
85
|
+
name = overrideName;
|
|
86
|
+
overrideName = null;
|
|
87
|
+
}
|
|
88
|
+
// Collect regular files only ('0' and '\0' are regular file type flags).
|
|
89
|
+
if (name && (typeFlag === '0' || typeFlag === '\0' || typeFlag === '')) {
|
|
90
|
+
items.push({ name, buffer: content.slice().buffer });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// File content is padded to a multiple of 512 bytes.
|
|
94
|
+
offset += Math.ceil(size / 512) * 512;
|
|
95
|
+
}
|
|
96
|
+
return items;
|
|
97
|
+
}
|
|
98
|
+
exports.readTarItems = readTarItems;
|
|
6
99
|
/**
|
|
7
100
|
* Unpacks the .tar.gz (odbx format) file and returns the items.
|
|
8
101
|
*
|
|
102
|
+
* Works in both the browser and Node.js: decompression uses `fflate` and the TAR archive is read by
|
|
103
|
+
* {@link readTarItems}, so it does not depend on any browser-only API.
|
|
104
|
+
*
|
|
9
105
|
* @param data - The .tar.gz (odbx format) file.
|
|
10
106
|
* @returns - The items in the .tar.gz file.
|
|
11
107
|
*/
|
|
12
108
|
function unpackBundle(data) {
|
|
13
109
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (manifestJson) {
|
|
25
|
-
const decoder = new TextDecoder('utf-8');
|
|
26
|
-
const content = decoder.decode(manifestJson.buffer);
|
|
27
|
-
const manifest = JSON.parse(content);
|
|
28
|
-
images = manifest.map((m) => m.RepoTags).reduce((a, b) => a.concat(b), []);
|
|
29
|
-
}
|
|
30
|
-
const packages = items.filter((item) => item.name.match(/\/package(.*).zip/));
|
|
31
|
-
return {
|
|
32
|
-
hasCache,
|
|
33
|
-
images,
|
|
34
|
-
items,
|
|
35
|
-
packages,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
return { hasCache: false, images: [], items: [], packages: [] };
|
|
110
|
+
const buffer = data instanceof ArrayBuffer ? data : yield data.arrayBuffer();
|
|
111
|
+
const archive = (0, fflate_1.gunzipSync)(new Uint8Array(buffer));
|
|
112
|
+
const items = readTarItems(archive);
|
|
113
|
+
const hasCache = items.some((item) => item.name.startsWith('cache/'));
|
|
114
|
+
let images = [];
|
|
115
|
+
const manifestJson = items.find((item) => item.name.match(/manifest.json$/));
|
|
116
|
+
if (manifestJson) {
|
|
117
|
+
const content = (0, fflate_1.strFromU8)(new Uint8Array(manifestJson.buffer));
|
|
118
|
+
const manifest = JSON.parse(content);
|
|
119
|
+
images = manifest.map((m) => m.RepoTags).reduce((a, b) => a.concat(b), []);
|
|
40
120
|
}
|
|
121
|
+
const packages = items.filter((item) => item.name.match(/\/package(.*).zip/));
|
|
122
|
+
return {
|
|
123
|
+
hasCache,
|
|
124
|
+
images,
|
|
125
|
+
items,
|
|
126
|
+
packages,
|
|
127
|
+
};
|
|
41
128
|
});
|
|
42
129
|
}
|
|
43
130
|
exports.unpackBundle = unpackBundle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unpack-bundle.js","sourceRoot":"","sources":["../../../../../libs/motion-master-client/src/lib/unpack-bundle.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"unpack-bundle.js","sourceRoot":"","sources":["../../../../../libs/motion-master-client/src/lib/unpack-bundle.ts"],"names":[],"mappings":";;;;AAAA,mCAA+C;AAO/C;;;;GAIG;AAC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