@loaders.gl/zip 4.2.0-alpha.4 → 4.2.0-alpha.6
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/dist/dist.dev.js +919 -523
- package/dist/dist.min.js +25 -0
- package/dist/filesystems/IndexedArchive.js +26 -12
- package/dist/filesystems/zip-filesystem.d.ts +2 -2
- package/dist/filesystems/zip-filesystem.d.ts.map +1 -1
- package/dist/filesystems/zip-filesystem.js +125 -88
- package/dist/hash-file-utility.d.ts +1 -1
- package/dist/hash-file-utility.d.ts.map +1 -1
- package/dist/hash-file-utility.js +85 -42
- package/dist/index.cjs +64 -128
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +12 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/lib/tar/header.d.ts +1 -1
- package/dist/lib/tar/header.d.ts.map +1 -1
- package/dist/lib/tar/header.js +69 -33
- package/dist/lib/tar/tar.d.ts +1 -1
- package/dist/lib/tar/tar.d.ts.map +1 -1
- package/dist/lib/tar/tar.js +124 -106
- package/dist/lib/tar/types.js +3 -1
- package/dist/lib/tar/utils.js +45 -18
- package/dist/parse-zip/cd-file-header.d.ts +1 -1
- package/dist/parse-zip/cd-file-header.d.ts.map +1 -1
- package/dist/parse-zip/cd-file-header.js +239 -177
- package/dist/parse-zip/end-of-central-directory.js +247 -158
- package/dist/parse-zip/local-file-header.d.ts +1 -1
- package/dist/parse-zip/local-file-header.d.ts.map +1 -1
- package/dist/parse-zip/local-file-header.js +143 -102
- package/dist/parse-zip/search-from-the-end.js +27 -13
- package/dist/parse-zip/zip-composition.js +142 -92
- package/dist/parse-zip/zip64-info-generation.js +64 -41
- package/dist/tar-builder.d.ts +1 -1
- package/dist/tar-builder.d.ts.map +1 -1
- package/dist/tar-builder.js +32 -29
- package/dist/zip-loader.js +52 -41
- package/dist/zip-writer.js +40 -40
- package/package.json +11 -7
- package/src/filesystems/zip-filesystem.ts +4 -0
- package/dist/filesystems/IndexedArchive.js.map +0 -1
- package/dist/filesystems/zip-filesystem.js.map +0 -1
- package/dist/hash-file-utility.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/tar/header.js.map +0 -1
- package/dist/lib/tar/tar.js.map +0 -1
- package/dist/lib/tar/types.js.map +0 -1
- package/dist/lib/tar/utils.js.map +0 -1
- package/dist/parse-zip/cd-file-header.js.map +0 -1
- package/dist/parse-zip/end-of-central-directory.js.map +0 -1
- package/dist/parse-zip/local-file-header.js.map +0 -1
- package/dist/parse-zip/search-from-the-end.js.map +0 -1
- package/dist/parse-zip/zip-composition.js.map +0 -1
- package/dist/parse-zip/zip64-info-generation.js.map +0 -1
- package/dist/tar-builder.js.map +0 -1
- package/dist/zip-loader.js.map +0 -1
- package/dist/zip-writer.js.map +0 -1
package/dist/lib/tar/tar.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// This file is derived from the tar-js code base under MIT license
|
|
5
|
+
// See https://github.com/beatgammit/tar-js/blob/master/LICENSE
|
|
6
|
+
/*
|
|
7
|
+
* tar-js
|
|
8
|
+
* MIT (c) 2011 T. Jameson Little
|
|
9
|
+
*/
|
|
1
10
|
import { clean, pad, stringToUint8 } from "./utils.js";
|
|
2
11
|
import { format } from "./header.js";
|
|
3
12
|
let blockSize;
|
|
@@ -5,113 +14,122 @@ let headerLength;
|
|
|
5
14
|
let inputLength;
|
|
6
15
|
const recordSize = 512;
|
|
7
16
|
class Tar {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (typeof input === 'string') {
|
|
25
|
-
input = stringToUint8(input);
|
|
26
|
-
} else if (input.constructor && input.constructor !== Uint8Array.prototype.constructor) {
|
|
27
|
-
const errorInputMatch = /function\s*([$A-Za-z_][0-9A-Za-z_]*)\s*\(/.exec(input.constructor.toString());
|
|
28
|
-
const errorInput = errorInputMatch && errorInputMatch[1];
|
|
29
|
-
const errorMessage = `Invalid input type. You gave me: ${errorInput}`;
|
|
30
|
-
throw errorMessage;
|
|
17
|
+
written;
|
|
18
|
+
out;
|
|
19
|
+
blocks = [];
|
|
20
|
+
length;
|
|
21
|
+
/**
|
|
22
|
+
* @param [recordsPerBlock]
|
|
23
|
+
*/
|
|
24
|
+
constructor(recordsPerBlock) {
|
|
25
|
+
this.written = 0;
|
|
26
|
+
blockSize = (recordsPerBlock || 20) * recordSize;
|
|
27
|
+
this.out = clean(blockSize);
|
|
28
|
+
this.blocks = [];
|
|
29
|
+
this.length = 0;
|
|
30
|
+
this.save = this.save.bind(this);
|
|
31
|
+
this.clear = this.clear.bind(this);
|
|
32
|
+
this.append = this.append.bind(this);
|
|
31
33
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
chunks.push({
|
|
80
|
-
blocks: chunk,
|
|
81
|
-
length
|
|
34
|
+
/**
|
|
35
|
+
* Append a file to the tar archive
|
|
36
|
+
* @param filepath
|
|
37
|
+
* @param input
|
|
38
|
+
* @param [opts]
|
|
39
|
+
*/
|
|
40
|
+
// eslint-disable-next-line complexity
|
|
41
|
+
append(filepath, input, opts) {
|
|
42
|
+
let checksum;
|
|
43
|
+
if (typeof input === 'string') {
|
|
44
|
+
input = stringToUint8(input);
|
|
45
|
+
}
|
|
46
|
+
else if (input.constructor && input.constructor !== Uint8Array.prototype.constructor) {
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
const errorInputMatch = /function\s*([$A-Za-z_][0-9A-Za-z_]*)\s*\(/.exec(input.constructor.toString());
|
|
49
|
+
const errorInput = errorInputMatch && errorInputMatch[1];
|
|
50
|
+
const errorMessage = `Invalid input type. You gave me: ${errorInput}`;
|
|
51
|
+
throw errorMessage;
|
|
52
|
+
}
|
|
53
|
+
opts = opts || {};
|
|
54
|
+
const mode = opts.mode || parseInt('777', 8) & 0xfff;
|
|
55
|
+
const mtime = opts.mtime || Math.floor(Number(new Date()) / 1000);
|
|
56
|
+
const uid = opts.uid || 0;
|
|
57
|
+
const gid = opts.gid || 0;
|
|
58
|
+
const data = {
|
|
59
|
+
fileName: filepath,
|
|
60
|
+
fileMode: pad(mode, 7),
|
|
61
|
+
uid: pad(uid, 7),
|
|
62
|
+
gid: pad(gid, 7),
|
|
63
|
+
fileSize: pad(input.length, 11),
|
|
64
|
+
mtime: pad(mtime, 11),
|
|
65
|
+
checksum: ' ',
|
|
66
|
+
// 0 = just a file
|
|
67
|
+
type: '0',
|
|
68
|
+
ustar: 'ustar ',
|
|
69
|
+
owner: opts.owner || '',
|
|
70
|
+
group: opts.group || ''
|
|
71
|
+
};
|
|
72
|
+
// calculate the checksum
|
|
73
|
+
checksum = 0;
|
|
74
|
+
Object.keys(data).forEach((key) => {
|
|
75
|
+
let i;
|
|
76
|
+
const value = data[key];
|
|
77
|
+
let length;
|
|
78
|
+
for (i = 0, length = value.length; i < length; i += 1) {
|
|
79
|
+
checksum += value.charCodeAt(i);
|
|
80
|
+
}
|
|
82
81
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
82
|
+
data.checksum = `${pad(checksum, 6)}\u0000 `;
|
|
83
|
+
const headerArr = format(data);
|
|
84
|
+
headerLength = Math.ceil(headerArr.length / recordSize) * recordSize;
|
|
85
|
+
inputLength = Math.ceil(input.length / recordSize) * recordSize;
|
|
86
|
+
this.blocks.push({
|
|
87
|
+
header: headerArr,
|
|
88
|
+
input,
|
|
89
|
+
headerLength,
|
|
90
|
+
inputLength
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Compiling data to a Blob object
|
|
95
|
+
* @returns {Blob}
|
|
96
|
+
*/
|
|
97
|
+
save() {
|
|
98
|
+
const buffers = [];
|
|
99
|
+
const chunks = new Array();
|
|
100
|
+
let length = 0;
|
|
101
|
+
const max = Math.pow(2, 20);
|
|
102
|
+
let chunk = new Array();
|
|
103
|
+
this.blocks.forEach((b = []) => {
|
|
104
|
+
if (length + b.headerLength + b.inputLength > max) {
|
|
105
|
+
chunks.push({ blocks: chunk, length });
|
|
106
|
+
chunk = [];
|
|
107
|
+
length = 0;
|
|
108
|
+
}
|
|
109
|
+
chunk.push(b);
|
|
110
|
+
length += b.headerLength + b.inputLength;
|
|
111
|
+
});
|
|
112
|
+
chunks.push({ blocks: chunk, length });
|
|
113
|
+
chunks.forEach((c = []) => {
|
|
114
|
+
const buffer = new Uint8Array(c.length);
|
|
115
|
+
let written = 0;
|
|
116
|
+
c.blocks.forEach((b = []) => {
|
|
117
|
+
buffer.set(b.header, written);
|
|
118
|
+
written += b.headerLength;
|
|
119
|
+
buffer.set(b.input, written);
|
|
120
|
+
written += b.inputLength;
|
|
121
|
+
});
|
|
122
|
+
buffers.push(buffer);
|
|
123
|
+
});
|
|
124
|
+
buffers.push(new Uint8Array(2 * recordSize));
|
|
125
|
+
return new Blob(buffers, { type: 'octet/stream' });
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Clear the data by its blocksize
|
|
129
|
+
*/
|
|
130
|
+
clear() {
|
|
131
|
+
this.written = 0;
|
|
132
|
+
this.out = clean(blockSize);
|
|
133
|
+
}
|
|
115
134
|
}
|
|
116
135
|
export default Tar;
|
|
117
|
-
//# sourceMappingURL=tar.js.map
|
package/dist/lib/tar/types.js
CHANGED
package/dist/lib/tar/utils.js
CHANGED
|
@@ -1,24 +1,51 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// This file is derived from the tar-js code base under MIT license
|
|
5
|
+
// See https://github.com/beatgammit/tar-js/blob/master/LICENSE
|
|
6
|
+
/*
|
|
7
|
+
* tar-js
|
|
8
|
+
* MIT (c) 2011 T. Jameson Little
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Returns the memory area specified by length
|
|
12
|
+
* @param length
|
|
13
|
+
* @returns {Uint8Array}
|
|
14
|
+
*/
|
|
1
15
|
export function clean(length) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
16
|
+
let i;
|
|
17
|
+
const buffer = new Uint8Array(length);
|
|
18
|
+
for (i = 0; i < length; i += 1) {
|
|
19
|
+
buffer[i] = 0;
|
|
20
|
+
}
|
|
21
|
+
return buffer;
|
|
8
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Converting data to a string
|
|
25
|
+
* @param num
|
|
26
|
+
* @param bytes
|
|
27
|
+
* @param base
|
|
28
|
+
* @returns string
|
|
29
|
+
*/
|
|
9
30
|
export function pad(num, bytes, base) {
|
|
10
|
-
|
|
11
|
-
|
|
31
|
+
const numStr = num.toString(base || 8);
|
|
32
|
+
return '000000000000'.substr(numStr.length + 12 - bytes) + numStr;
|
|
12
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Converting input to binary data
|
|
36
|
+
* @param input
|
|
37
|
+
* @param out
|
|
38
|
+
* @param offset
|
|
39
|
+
* @returns {Uint8Array}
|
|
40
|
+
*/
|
|
13
41
|
export function stringToUint8(input, out, offset) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
42
|
+
let i;
|
|
43
|
+
let length;
|
|
44
|
+
out = out || clean(input.length);
|
|
45
|
+
offset = offset || 0;
|
|
46
|
+
for (i = 0, length = input.length; i < length; i += 1) {
|
|
47
|
+
out[offset] = input.charCodeAt(i);
|
|
48
|
+
offset += 1;
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
23
51
|
}
|
|
24
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FileProvider } from '@loaders.gl/loader-utils';
|
|
2
|
-
import { ZipSignature } from
|
|
2
|
+
import { ZipSignature } from "./search-from-the-end.js";
|
|
3
3
|
/**
|
|
4
4
|
* zip central directory file header info
|
|
5
5
|
* according to https://en.wikipedia.org/wiki/ZIP_(file_format)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cd-file-header.d.ts","sourceRoot":"","sources":["../../src/parse-zip/cd-file-header.ts"],"names":[],"m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