@loaders.gl/zip 4.1.0-alpha.2 → 4.1.0-alpha.4
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 +155 -51
- package/dist/filesystems/zip-filesystem.d.ts.map +1 -1
- package/dist/filesystems/zip-filesystem.js.map +1 -1
- package/dist/hash-file-utility.d.ts.map +1 -1
- package/dist/hash-file-utility.js.map +1 -1
- package/dist/index.cjs +171 -49
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/tar/header.d.ts.map +1 -1
- package/dist/lib/tar/header.js.map +1 -1
- package/dist/lib/tar/tar.d.ts.map +1 -1
- package/dist/lib/tar/tar.js.map +1 -1
- package/dist/lib/tar/types.d.ts.map +1 -1
- package/dist/lib/tar/types.js.map +1 -1
- package/dist/lib/tar/utils.d.ts.map +1 -1
- package/dist/lib/tar/utils.js.map +1 -1
- 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 +4 -4
- package/dist/parse-zip/cd-file-header.js.map +1 -1
- package/dist/parse-zip/end-of-central-directory.d.ts +19 -0
- package/dist/parse-zip/end-of-central-directory.d.ts.map +1 -1
- package/dist/parse-zip/end-of-central-directory.js +42 -8
- package/dist/parse-zip/end-of-central-directory.js.map +1 -1
- package/dist/parse-zip/local-file-header.d.ts +16 -0
- package/dist/parse-zip/local-file-header.d.ts.map +1 -1
- package/dist/parse-zip/local-file-header.js +73 -1
- package/dist/parse-zip/local-file-header.js.map +1 -1
- package/dist/parse-zip/search-from-the-end.d.ts.map +1 -1
- package/dist/parse-zip/search-from-the-end.js.map +1 -1
- package/dist/parse-zip/zip-compozition.d.ts +8 -0
- package/dist/parse-zip/zip-compozition.d.ts.map +1 -0
- package/dist/parse-zip/zip-compozition.js +43 -0
- package/dist/parse-zip/zip-compozition.js.map +1 -0
- package/dist/parse-zip/zip64-info-generation.d.ts +5 -8
- package/dist/parse-zip/zip64-info-generation.d.ts.map +1 -1
- package/dist/parse-zip/zip64-info-generation.js +6 -3
- package/dist/parse-zip/zip64-info-generation.js.map +1 -1
- package/dist/tar-builder.d.ts.map +1 -1
- package/dist/tar-builder.js.map +1 -1
- package/dist/zip-loader.d.ts.map +1 -1
- package/dist/zip-loader.js +1 -1
- package/dist/zip-loader.js.map +1 -1
- package/dist/zip-writer.d.ts +2 -2
- package/dist/zip-writer.d.ts.map +1 -1
- package/dist/zip-writer.js +22 -7
- package/dist/zip-writer.js.map +1 -1
- package/package.json +5 -5
- package/src/filesystems/zip-filesystem.ts +2 -1
- package/src/hash-file-utility.ts +2 -1
- package/src/index.ts +4 -2
- package/src/lib/tar/header.ts +2 -1
- package/src/lib/tar/tar.ts +2 -1
- package/src/lib/tar/types.ts +2 -1
- package/src/lib/tar/utils.ts +2 -1
- package/src/parse-zip/cd-file-header.ts +8 -6
- package/src/parse-zip/end-of-central-directory.ts +97 -9
- package/src/parse-zip/local-file-header.ts +128 -2
- package/src/parse-zip/search-from-the-end.ts +2 -1
- package/src/parse-zip/zip-compozition.ts +113 -0
- package/src/parse-zip/zip64-info-generation.ts +20 -4
- package/src/tar-builder.ts +2 -1
- package/src/zip-loader.ts +2 -1
- package/src/zip-writer.ts +24 -10
package/src/zip-writer.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
|
-
import type {
|
|
5
|
+
import type {WriterWithEncoder, WriterOptions} from '@loaders.gl/loader-utils';
|
|
5
6
|
import JSZip, {JSZipGeneratorOptions} from 'jszip';
|
|
6
7
|
|
|
8
|
+
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
9
|
+
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
10
|
+
|
|
7
11
|
export type ZipWriterOptions = WriterOptions & {
|
|
8
12
|
zip?: {
|
|
9
13
|
onUpdate?: (metadata: {percent: number}) => void;
|
|
@@ -15,19 +19,27 @@ export type ZipWriterOptions = WriterOptions & {
|
|
|
15
19
|
/**
|
|
16
20
|
* Zip exporter
|
|
17
21
|
*/
|
|
18
|
-
export const ZipWriter:
|
|
22
|
+
export const ZipWriter: WriterWithEncoder<Record<string, ArrayBuffer>, never, ZipWriterOptions> = {
|
|
19
23
|
name: 'Zip Archive',
|
|
24
|
+
id: 'zip',
|
|
25
|
+
module: 'zip',
|
|
26
|
+
version: VERSION,
|
|
20
27
|
extensions: ['zip'],
|
|
21
28
|
category: 'archive',
|
|
22
29
|
mimeTypes: ['application/zip'],
|
|
23
|
-
|
|
30
|
+
options: {
|
|
31
|
+
zip: {
|
|
32
|
+
onUpdate: () => {}
|
|
33
|
+
},
|
|
34
|
+
jszip: {}
|
|
35
|
+
},
|
|
24
36
|
encode: encodeZipAsync
|
|
25
37
|
};
|
|
26
38
|
|
|
27
39
|
async function encodeZipAsync(
|
|
28
40
|
fileMap: Record<string, ArrayBuffer>,
|
|
29
41
|
options: ZipWriterOptions = {}
|
|
30
|
-
) {
|
|
42
|
+
): Promise<ArrayBuffer> {
|
|
31
43
|
const jsZip = new JSZip();
|
|
32
44
|
// add files to the zip
|
|
33
45
|
for (const subFileName in fileMap) {
|
|
@@ -38,14 +50,16 @@ async function encodeZipAsync(
|
|
|
38
50
|
jsZip.file(subFileName, subFileData, options?.jszip || {});
|
|
39
51
|
}
|
|
40
52
|
|
|
41
|
-
|
|
42
|
-
const jszipOptions: JSZipGeneratorOptions = {...options?.jszip,
|
|
43
|
-
const {onUpdate = () => {}} = options;
|
|
53
|
+
const zipOptions = {...ZipWriter.options.zip, ...options?.zip};
|
|
54
|
+
const jszipOptions: JSZipGeneratorOptions = {...ZipWriter.options?.jszip, ...options.jszip};
|
|
44
55
|
|
|
45
56
|
try {
|
|
46
|
-
return await jsZip.generateAsync(
|
|
57
|
+
return await jsZip.generateAsync(
|
|
58
|
+
{...jszipOptions, type: 'arraybuffer'}, // generate an arraybuffer
|
|
59
|
+
zipOptions.onUpdate
|
|
60
|
+
);
|
|
47
61
|
} catch (error) {
|
|
48
|
-
options.log.error(`Unable to
|
|
62
|
+
options.log.error(`Unable to encode zip archive: ${error}`);
|
|
49
63
|
throw error;
|
|
50
64
|
}
|
|
51
65
|
}
|