@loaders.gl/zip 4.0.0-alpha.22 → 4.0.0-alpha.24

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 (109) hide show
  1. package/dist/dist.min.js +156 -181
  2. package/dist/es5/filesystems/zip-filesystem.js +4 -6
  3. package/dist/es5/filesystems/zip-filesystem.js.map +1 -1
  4. package/dist/es5/hash-file-utility.js.map +1 -1
  5. package/dist/es5/index.js +2 -17
  6. package/dist/es5/index.js.map +1 -1
  7. package/dist/es5/parse-zip/cd-file-header.js.map +1 -1
  8. package/dist/es5/parse-zip/end-of-central-directory.js.map +1 -1
  9. package/dist/es5/parse-zip/local-file-header.js.map +1 -1
  10. package/dist/es5/parse-zip/search-from-the-end.js.map +1 -1
  11. package/dist/es5/tar-builder.js +8 -8
  12. package/dist/es5/tar-builder.js.map +1 -1
  13. package/dist/es5/zip-loader.js +2 -4
  14. package/dist/es5/zip-loader.js.map +1 -1
  15. package/dist/es5/zip-writer.js +19 -10
  16. package/dist/es5/zip-writer.js.map +1 -1
  17. package/dist/esm/filesystems/zip-filesystem.js +3 -3
  18. package/dist/esm/filesystems/zip-filesystem.js.map +1 -1
  19. package/dist/esm/hash-file-utility.js.map +1 -1
  20. package/dist/esm/index.js +1 -3
  21. package/dist/esm/index.js.map +1 -1
  22. package/dist/esm/parse-zip/cd-file-header.js.map +1 -1
  23. package/dist/esm/parse-zip/end-of-central-directory.js.map +1 -1
  24. package/dist/esm/parse-zip/local-file-header.js.map +1 -1
  25. package/dist/esm/parse-zip/search-from-the-end.js.map +1 -1
  26. package/dist/esm/tar-builder.js +2 -2
  27. package/dist/esm/tar-builder.js.map +1 -1
  28. package/dist/esm/zip-loader.js +1 -2
  29. package/dist/esm/zip-loader.js.map +1 -1
  30. package/dist/esm/zip-writer.js +8 -5
  31. package/dist/esm/zip-writer.js.map +1 -1
  32. package/dist/filesystems/zip-filesystem.d.ts +2 -2
  33. package/dist/filesystems/zip-filesystem.d.ts.map +1 -1
  34. package/dist/hash-file-utility.d.ts +1 -1
  35. package/dist/hash-file-utility.d.ts.map +1 -1
  36. package/dist/index.d.ts +1 -4
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/parse-zip/cd-file-header.d.ts +1 -1
  39. package/dist/parse-zip/cd-file-header.d.ts.map +1 -1
  40. package/dist/parse-zip/end-of-central-directory.d.ts +1 -1
  41. package/dist/parse-zip/end-of-central-directory.d.ts.map +1 -1
  42. package/dist/parse-zip/local-file-header.d.ts +1 -1
  43. package/dist/parse-zip/local-file-header.d.ts.map +1 -1
  44. package/dist/parse-zip/search-from-the-end.d.ts +1 -1
  45. package/dist/parse-zip/search-from-the-end.d.ts.map +1 -1
  46. package/dist/tar-builder.d.ts +2 -2
  47. package/dist/tar-builder.d.ts.map +1 -1
  48. package/dist/zip-loader.d.ts +0 -1
  49. package/dist/zip-loader.d.ts.map +1 -1
  50. package/dist/zip-writer.d.ts +12 -2
  51. package/dist/zip-writer.d.ts.map +1 -1
  52. package/package.json +4 -9
  53. package/src/filesystems/zip-filesystem.ts +3 -3
  54. package/src/hash-file-utility.ts +1 -1
  55. package/src/index.ts +3 -5
  56. package/src/parse-zip/cd-file-header.ts +1 -1
  57. package/src/parse-zip/end-of-central-directory.ts +1 -1
  58. package/src/parse-zip/local-file-header.ts +1 -1
  59. package/src/parse-zip/search-from-the-end.ts +1 -1
  60. package/src/tar-builder.ts +2 -2
  61. package/src/zip-loader.ts +2 -3
  62. package/src/zip-writer.ts +23 -10
  63. package/dist/bundle.js +0 -5
  64. package/dist/es5/file-provider/data-view-file.js +0 -146
  65. package/dist/es5/file-provider/data-view-file.js.map +0 -1
  66. package/dist/es5/file-provider/file-handle-file.js +0 -234
  67. package/dist/es5/file-provider/file-handle-file.js.map +0 -1
  68. package/dist/es5/file-provider/file-handle.js +0 -101
  69. package/dist/es5/file-provider/file-handle.js.map +0 -1
  70. package/dist/es5/file-provider/file-provider.js +0 -11
  71. package/dist/es5/file-provider/file-provider.js.map +0 -1
  72. package/dist/esm/file-provider/data-view-file.js +0 -33
  73. package/dist/esm/file-provider/data-view-file.js.map +0 -1
  74. package/dist/esm/file-provider/file-handle-file.js +0 -57
  75. package/dist/esm/file-provider/file-handle-file.js.map +0 -1
  76. package/dist/esm/file-provider/file-handle.js +0 -37
  77. package/dist/esm/file-provider/file-handle.js.map +0 -1
  78. package/dist/esm/file-provider/file-provider.js +0 -4
  79. package/dist/esm/file-provider/file-provider.js.map +0 -1
  80. package/dist/file-provider/data-view-file.d.ts +0 -37
  81. package/dist/file-provider/data-view-file.d.ts.map +0 -1
  82. package/dist/file-provider/data-view-file.js +0 -63
  83. package/dist/file-provider/file-handle-file.d.ts +0 -53
  84. package/dist/file-provider/file-handle-file.d.ts.map +0 -1
  85. package/dist/file-provider/file-handle-file.js +0 -90
  86. package/dist/file-provider/file-handle.d.ts +0 -40
  87. package/dist/file-provider/file-handle.d.ts.map +0 -1
  88. package/dist/file-provider/file-handle.js +0 -57
  89. package/dist/file-provider/file-provider.d.ts +0 -45
  90. package/dist/file-provider/file-provider.d.ts.map +0 -1
  91. package/dist/file-provider/file-provider.js +0 -13
  92. package/dist/filesystems/zip-filesystem.js +0 -128
  93. package/dist/hash-file-utility.js +0 -88
  94. package/dist/index.js +0 -34
  95. package/dist/lib/tar/header.js +0 -99
  96. package/dist/lib/tar/tar.js +0 -131
  97. package/dist/lib/tar/types.js +0 -2
  98. package/dist/lib/tar/utils.js +0 -54
  99. package/dist/parse-zip/cd-file-header.js +0 -68
  100. package/dist/parse-zip/end-of-central-directory.js +0 -40
  101. package/dist/parse-zip/local-file-header.js +0 -55
  102. package/dist/parse-zip/search-from-the-end.js +0 -31
  103. package/dist/tar-builder.js +0 -38
  104. package/dist/zip-loader.js +0 -61
  105. package/dist/zip-writer.js +0 -37
  106. package/src/file-provider/data-view-file.ts +0 -72
  107. package/src/file-provider/file-handle-file.ts +0 -114
  108. package/src/file-provider/file-handle.ts +0 -73
  109. package/src/file-provider/file-provider.ts +0 -56
@@ -1,61 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports._typecheckZipLoader = exports.ZipLoader = void 0;
7
- const jszip_1 = __importDefault(require("jszip"));
8
- // __VERSION__ is injected by babel-plugin-version-inline
9
- // @ts-ignore TS2304: Cannot find name '__VERSION__'.
10
- const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
11
- exports.ZipLoader = {
12
- id: 'zip',
13
- module: 'zip',
14
- name: 'Zip Archive',
15
- version: VERSION,
16
- extensions: ['zip'],
17
- mimeTypes: ['application/zip'],
18
- category: 'archive',
19
- tests: ['PK'],
20
- options: {},
21
- parse: parseZipAsync
22
- };
23
- // TODO - Could return a map of promises, perhaps as an option...
24
- async function parseZipAsync(data, options = {}) {
25
- const promises = [];
26
- const fileMap = {};
27
- try {
28
- const jsZip = new jszip_1.default();
29
- const zip = await jsZip.loadAsync(data, options);
30
- // start to load each file in this zip
31
- zip.forEach((relativePath, zipEntry) => {
32
- const subFilename = zipEntry.name;
33
- const promise = loadZipEntry(jsZip, subFilename, options).then((arrayBufferOrError) => {
34
- fileMap[relativePath] = arrayBufferOrError;
35
- });
36
- // Ensure Promise.all doesn't ignore rejected promises.
37
- promises.push(promise);
38
- });
39
- await Promise.all(promises);
40
- return fileMap;
41
- }
42
- catch (error) {
43
- // @ts-ignore
44
- options.log.error(`Unable to read zip archive: ${error}`);
45
- throw error;
46
- }
47
- }
48
- async function loadZipEntry(jsZip, subFilename, options = {}) {
49
- // jszip supports both arraybuffer and text, the main loaders.gl types
50
- // https://stuk.github.io/jszip/documentation/api_zipobject/async.html
51
- try {
52
- const arrayBuffer = await jsZip.file(subFilename).async(options.dataType || 'arraybuffer');
53
- return arrayBuffer;
54
- }
55
- catch (error) {
56
- options.log.error(`Unable to read ${subFilename} from zip archive: ${error}`);
57
- // Store error in place of data in map
58
- return error;
59
- }
60
- }
61
- exports._typecheckZipLoader = exports.ZipLoader;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ZipWriter = void 0;
7
- const jszip_1 = __importDefault(require("jszip"));
8
- /**
9
- * Zip exporter
10
- */
11
- exports.ZipWriter = {
12
- name: 'Zip Archive',
13
- extensions: ['zip'],
14
- category: 'archive',
15
- mimeTypes: ['application/zip'],
16
- // @ts-ignore
17
- encode: encodeZipAsync
18
- };
19
- async function encodeZipAsync(fileMap, options = {}) {
20
- const jsZip = new jszip_1.default();
21
- // add files to the zip
22
- for (const subFileName in fileMap) {
23
- const subFileData = fileMap[subFileName];
24
- // jszip supports both arraybuffer and string data (the main loaders.gl types)
25
- // https://stuk.github.io/jszip/documentation/api_zipobject/async.html
26
- jsZip.file(subFileName, subFileData, options);
27
- }
28
- // always generate the full zip as an arraybuffer
29
- options = Object.assign({}, options, {
30
- type: 'arraybuffer'
31
- });
32
- const { onUpdate = () => { } } = options;
33
- return jsZip.generateAsync(options, onUpdate).catch((error) => {
34
- options.log.error(`Unable to write zip archive: ${error}`);
35
- throw error;
36
- });
37
- }
@@ -1,72 +0,0 @@
1
- import {FileProvider} from './file-provider';
2
-
3
- /**
4
- * Checks if bigint can be converted to number and convert it if possible
5
- * @param bigint bigint to be converted
6
- * @returns number
7
- */
8
- const toNumber = (bigint: bigint) => {
9
- if (bigint > Number.MAX_SAFE_INTEGER) {
10
- throw new Error('Offset is out of bounds');
11
- }
12
- return Number(bigint);
13
- };
14
-
15
- /** Provides file data using DataView */
16
- export class DataViewFile implements FileProvider {
17
- /** The DataView from which data is provided */
18
- private file: DataView;
19
-
20
- constructor(file: DataView) {
21
- this.file = file;
22
- }
23
-
24
- // eslint-disable-next-line @typescript-eslint/no-empty-function
25
- async destroy(): Promise<void> {}
26
-
27
- /**
28
- * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
29
- * @param offset The offset, in bytes, from the start of the file where to read the data.
30
- */
31
- async getUint8(offset: bigint): Promise<number> {
32
- return this.file.getUint8(toNumber(offset));
33
- }
34
-
35
- /**
36
- * Gets an unsigned 16-bit intege at the specified byte offset from the start of the file.
37
- * @param offset The offset, in bytes, from the start of the file where to read the data.
38
- */
39
- async getUint16(offset: bigint): Promise<number> {
40
- return this.file.getUint16(toNumber(offset), true);
41
- }
42
-
43
- /**
44
- * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
45
- * @param offset The offset, in bytes, from the start of the file where to read the data.
46
- */
47
- async getUint32(offset: bigint): Promise<number> {
48
- return this.file.getUint32(toNumber(offset), true);
49
- }
50
-
51
- /**
52
- * Gets an unsigned 64-bit integer at the specified byte offset from the start of the file.
53
- * @param offset The offset, in bytes, from the start of the file where to read the data.
54
- */
55
- async getBigUint64(offset: bigint): Promise<bigint> {
56
- return this.file.getBigUint64(toNumber(offset), true);
57
- }
58
-
59
- /**
60
- * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
61
- * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.
62
- * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
63
- */
64
- async slice(startOffset: bigint, endOffset: bigint): Promise<ArrayBuffer> {
65
- return this.file.buffer.slice(toNumber(startOffset), toNumber(endOffset));
66
- }
67
-
68
- /** the length (in bytes) of the data. */
69
- get length() {
70
- return BigInt(this.file.byteLength);
71
- }
72
- }
@@ -1,114 +0,0 @@
1
- import {FileProvider} from '@loaders.gl/zip';
2
- import {FileHandle} from './file-handle';
3
-
4
- /**
5
- * Provides file data using node fs library
6
- */
7
- export class FileHandleFile implements FileProvider {
8
- /**
9
- * Returns a new copy of FileHandleFile
10
- * @param path The path to the file in file system
11
- */
12
- static async from(path: string): Promise<FileHandleFile> {
13
- const fileDescriptor = await FileHandle.open(path);
14
- return new FileHandleFile(fileDescriptor, fileDescriptor.stat.size);
15
- }
16
-
17
- /**
18
- * The FileHandle from which data is provided
19
- */
20
- private fileDescriptor: FileHandle;
21
-
22
- /**
23
- * The file length in bytes
24
- */
25
- private size: bigint;
26
-
27
- private constructor(fileDescriptor: FileHandle, size: bigint) {
28
- this.fileDescriptor = fileDescriptor;
29
- this.size = size;
30
- }
31
-
32
- /** Close file */
33
- async destroy(): Promise<void> {
34
- await this.fileDescriptor.close();
35
- }
36
-
37
- /**
38
- * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
39
- * @param offset The offset, in bytes, from the start of the file where to read the data.
40
- */
41
- async getUint8(offset: bigint): Promise<number> {
42
- const val = new Uint8Array(
43
- (await this.fileDescriptor.read(Buffer.alloc(1), 0, 1, offset)).buffer.buffer
44
- ).at(0);
45
- if (val === undefined) {
46
- throw new Error('something went wrong');
47
- }
48
- return val;
49
- }
50
-
51
- /**
52
- * Gets an unsigned 16-bit integer at the specified byte offset from the start of the file.
53
- * @param offset The offset, in bytes, from the start of the file where to read the data.
54
- */
55
- async getUint16(offset: bigint): Promise<number> {
56
- const val = new Uint16Array(
57
- (await this.fileDescriptor.read(Buffer.alloc(2), 0, 2, offset)).buffer.buffer
58
- ).at(0);
59
- if (val === undefined) {
60
- throw new Error('something went wrong');
61
- }
62
- return val;
63
- }
64
-
65
- /**
66
- * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
67
- * @param offset The offset, in bytes, from the start of the file where to read the data.
68
- */
69
- async getUint32(offset: bigint): Promise<number> {
70
- const val = new Uint32Array(
71
- (await this.fileDescriptor.read(Buffer.alloc(4), 0, 4, offset)).buffer.buffer
72
- ).at(0);
73
- if (val === undefined) {
74
- throw new Error('something went wrong');
75
- }
76
- return val;
77
- }
78
-
79
- /**
80
- * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
81
- * @param offset The offset, in bytes, from the start of the file where to read the data.
82
- */
83
- async getBigUint64(offset: bigint): Promise<bigint> {
84
- const val = new BigInt64Array(
85
- (await this.fileDescriptor.read(Buffer.alloc(8), 0, 8, offset)).buffer.buffer
86
- ).at(0);
87
- if (val === undefined) {
88
- throw new Error('something went wrong');
89
- }
90
- return val;
91
- }
92
-
93
- /**
94
- * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
95
- * @param startOffsset The offset, in byte, from the start of the file where to start reading the data.
96
- * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
97
- */
98
- async slice(startOffsset: bigint, endOffset: bigint): Promise<ArrayBuffer> {
99
- const bigLength = endOffset - startOffsset;
100
- if (bigLength > Number.MAX_SAFE_INTEGER) {
101
- throw new Error('too big slice');
102
- }
103
- const length = Number(bigLength);
104
- return (await this.fileDescriptor.read(Buffer.alloc(length), 0, length, startOffsset)).buffer
105
- .buffer;
106
- }
107
-
108
- /**
109
- * the length (in bytes) of the data.
110
- */
111
- get length(): bigint {
112
- return this.size;
113
- }
114
- }
@@ -1,73 +0,0 @@
1
- import {read, open, close, stat, BigIntStats} from 'fs';
2
-
3
- /** file reading result */
4
- export type FileReadResult = {
5
- /** amount of the bytes read */
6
- bytesRead: number;
7
- /** the buffer filled with data from file*/
8
- buffer: Buffer;
9
- };
10
-
11
- /** Object handling file info */
12
- export class FileHandle {
13
- private fileDescriptor: number;
14
- private stats: BigIntStats;
15
- private constructor(fileDescriptor: number, stats: BigIntStats) {
16
- this.fileDescriptor = fileDescriptor;
17
- this.stats = stats;
18
- }
19
- /**
20
- * Opens a `FileHandle`.
21
- *
22
- * @param path path to the file
23
- * @return Fulfills with a {FileHandle} object.
24
- */
25
-
26
- static open = async (path: string): Promise<FileHandle> => {
27
- const [fd, stats] = await Promise.all([
28
- new Promise<number>((s) => {
29
- open(path, undefined, undefined, (_err, fd) => s(fd));
30
- }),
31
- new Promise<BigIntStats>((s) => {
32
- stat(path, {bigint: true}, (_err, stats) => s(stats));
33
- })
34
- ]);
35
- return new FileHandle(fd, stats);
36
- };
37
-
38
- /** Close file */
39
- async close(): Promise<void> {
40
- return new Promise<void>((resolve) => {
41
- close(this.fileDescriptor, (_err) => resolve());
42
- });
43
- }
44
-
45
- /**
46
- * Reads data from the file and stores that in the given buffer.
47
- *
48
- * If the file is not modified concurrently, the end-of-file is reached when the
49
- * number of bytes read is zero.
50
- * @param buffer A buffer that will be filled with the file data read.
51
- * @param offset The location in the buffer at which to start filling.
52
- * @param length The number of bytes to read.
53
- * @param position The location where to begin reading data from the file. If `null`, data will be read from the current file position, and the position will be updated. If `position` is an
54
- * integer, the current file position will remain unchanged.
55
- * @return Fulfills upon success with a FileReadResult object
56
- */
57
- read = (
58
- buffer: Buffer,
59
- offset: number,
60
- length: number,
61
- position: number | bigint
62
- ): Promise<FileReadResult> => {
63
- return new Promise((s) => {
64
- read(this.fileDescriptor, buffer, offset, length, position, (_err, bytesRead, buffer) =>
65
- s({bytesRead, buffer})
66
- );
67
- });
68
- };
69
-
70
- get stat(): BigIntStats {
71
- return this.stats;
72
- }
73
- }
@@ -1,56 +0,0 @@
1
- /**
2
- * Interface for providing file data
3
- */
4
- export interface FileProvider {
5
- /**
6
- * Cleanup class data
7
- */
8
- destroy(): Promise<void>;
9
- /**
10
- * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
11
- * @param offset The offset, in bytes, from the start of the file where to read the data.
12
- */
13
- getUint8(offset: bigint): Promise<number>;
14
-
15
- /**
16
- * Gets an unsigned 16-bit integer at the specified byte offset from the start of the file.
17
- * @param offset The offset, in bytes, from the start of the file where to read the data.
18
- */
19
- getUint16(offset: bigint): Promise<number>;
20
-
21
- /**
22
- * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
23
- * @param offset The offset, in bytes, from the file of the view where to read the data.
24
- */
25
- getUint32(offset: bigint): Promise<number>;
26
-
27
- /**
28
- * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
29
- * @param offset The offset, in byte, from the file of the view where to read the data.
30
- */
31
- getBigUint64(offset: bigint): Promise<bigint>;
32
-
33
- /**
34
- * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
35
- * @param startOffset The offset, in bytes, from the start of the file where to start reading the data.
36
- * @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
37
- */
38
- slice(startOffset: bigint, endOffset: bigint): Promise<ArrayBuffer>;
39
-
40
- /**
41
- * the length (in bytes) of the data.
42
- */
43
- length: bigint;
44
- }
45
-
46
- /**
47
- * Check is the object has FileProvider members
48
- * @param fileProvider - tested object
49
- */
50
- export const isFileProvider = (fileProvider: unknown) => {
51
- return (
52
- (fileProvider as FileProvider)?.getUint8 &&
53
- (fileProvider as FileProvider)?.slice &&
54
- (fileProvider as FileProvider)?.length
55
- );
56
- };