@loaders.gl/zip 4.0.0-alpha.21 → 4.0.0-alpha.23
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.min.js +4650 -176
- package/dist/es5/filesystems/zip-filesystem.js +134 -102
- package/dist/es5/filesystems/zip-filesystem.js.map +1 -1
- package/dist/es5/hash-file-utility.js.map +1 -1
- package/dist/es5/index.js +6 -14
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/parse-zip/cd-file-header.js.map +1 -1
- package/dist/es5/parse-zip/end-of-central-directory.js.map +1 -1
- package/dist/es5/parse-zip/local-file-header.js.map +1 -1
- package/dist/es5/parse-zip/search-from-the-end.js.map +1 -1
- package/dist/es5/tar-builder.js +8 -8
- package/dist/es5/tar-builder.js.map +1 -1
- package/dist/es5/zip-loader.js +2 -4
- package/dist/es5/zip-loader.js.map +1 -1
- package/dist/esm/filesystems/zip-filesystem.js +18 -5
- package/dist/esm/filesystems/zip-filesystem.js.map +1 -1
- package/dist/esm/hash-file-utility.js.map +1 -1
- package/dist/esm/index.js +2 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/parse-zip/cd-file-header.js.map +1 -1
- package/dist/esm/parse-zip/end-of-central-directory.js.map +1 -1
- package/dist/esm/parse-zip/local-file-header.js.map +1 -1
- package/dist/esm/parse-zip/search-from-the-end.js.map +1 -1
- package/dist/esm/tar-builder.js +2 -2
- package/dist/esm/tar-builder.js.map +1 -1
- package/dist/esm/zip-loader.js +1 -2
- package/dist/esm/zip-loader.js.map +1 -1
- package/dist/filesystems/zip-filesystem.d.ts +4 -3
- package/dist/filesystems/zip-filesystem.d.ts.map +1 -1
- package/dist/filesystems/zip-filesystem.js +17 -8
- package/dist/hash-file-utility.d.ts +1 -1
- package/dist/hash-file-utility.d.ts.map +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -9
- 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/end-of-central-directory.d.ts +1 -1
- package/dist/parse-zip/end-of-central-directory.d.ts.map +1 -1
- 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/search-from-the-end.d.ts +1 -1
- package/dist/parse-zip/search-from-the-end.d.ts.map +1 -1
- package/dist/tar-builder.d.ts +2 -2
- package/dist/tar-builder.d.ts.map +1 -1
- package/dist/tar-builder.js +4 -3
- package/dist/zip-loader.d.ts +0 -1
- package/dist/zip-loader.d.ts.map +1 -1
- package/dist/zip-loader.js +1 -2
- package/package.json +4 -9
- package/src/filesystems/zip-filesystem.ts +16 -6
- package/src/hash-file-utility.ts +1 -1
- package/src/index.ts +5 -5
- package/src/parse-zip/cd-file-header.ts +1 -1
- package/src/parse-zip/end-of-central-directory.ts +1 -1
- package/src/parse-zip/local-file-header.ts +1 -1
- package/src/parse-zip/search-from-the-end.ts +1 -1
- package/src/tar-builder.ts +2 -2
- package/src/zip-loader.ts +0 -2
- package/dist/es5/file-provider/data-view-file.js +0 -146
- package/dist/es5/file-provider/data-view-file.js.map +0 -1
- package/dist/es5/file-provider/file-handle-file.js +0 -234
- package/dist/es5/file-provider/file-handle-file.js.map +0 -1
- package/dist/es5/file-provider/file-handle.js +0 -101
- package/dist/es5/file-provider/file-handle.js.map +0 -1
- package/dist/es5/file-provider/file-provider.js +0 -11
- package/dist/es5/file-provider/file-provider.js.map +0 -1
- package/dist/esm/file-provider/data-view-file.js +0 -33
- package/dist/esm/file-provider/data-view-file.js.map +0 -1
- package/dist/esm/file-provider/file-handle-file.js +0 -57
- package/dist/esm/file-provider/file-handle-file.js.map +0 -1
- package/dist/esm/file-provider/file-handle.js +0 -37
- package/dist/esm/file-provider/file-handle.js.map +0 -1
- package/dist/esm/file-provider/file-provider.js +0 -4
- package/dist/esm/file-provider/file-provider.js.map +0 -1
- package/dist/file-provider/data-view-file.d.ts +0 -37
- package/dist/file-provider/data-view-file.d.ts.map +0 -1
- package/dist/file-provider/data-view-file.js +0 -63
- package/dist/file-provider/file-handle-file.d.ts +0 -53
- package/dist/file-provider/file-handle-file.d.ts.map +0 -1
- package/dist/file-provider/file-handle-file.js +0 -90
- package/dist/file-provider/file-handle.d.ts +0 -40
- package/dist/file-provider/file-handle.d.ts.map +0 -1
- package/dist/file-provider/file-handle.js +0 -57
- package/dist/file-provider/file-provider.d.ts +0 -45
- package/dist/file-provider/file-provider.d.ts.map +0 -1
- package/dist/file-provider/file-provider.js +0 -13
- package/src/file-provider/data-view-file.ts +0 -72
- package/src/file-provider/file-handle-file.ts +0 -114
- package/src/file-provider/file-handle.ts +0 -73
- package/src/file-provider/file-provider.ts +0 -56
|
@@ -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
|
-
};
|