@loaders.gl/zip 4.0.0-alpha.20 → 4.0.0-alpha.21
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 +494 -119
- package/dist/es5/{parse-zip → file-provider}/data-view-file.js +46 -29
- package/dist/es5/file-provider/data-view-file.js.map +1 -0
- package/dist/es5/file-provider/file-handle-file.js +234 -0
- package/dist/es5/file-provider/file-handle-file.js.map +1 -0
- package/dist/es5/file-provider/file-handle.js +101 -0
- package/dist/es5/file-provider/file-handle.js.map +1 -0
- package/dist/es5/file-provider/file-provider.js +11 -0
- package/dist/es5/file-provider/file-provider.js.map +1 -0
- package/dist/es5/filesystems/zip-filesystem.js +340 -0
- package/dist/es5/filesystems/zip-filesystem.js.map +1 -0
- package/dist/es5/hash-file-utility.js +81 -1
- package/dist/es5/hash-file-utility.js.map +1 -1
- package/dist/es5/index.js +20 -1
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/parse-zip/cd-file-header.js +58 -16
- package/dist/es5/parse-zip/cd-file-header.js.map +1 -1
- package/dist/es5/parse-zip/end-of-central-directory.js +10 -12
- package/dist/es5/parse-zip/end-of-central-directory.js.map +1 -1
- package/dist/es5/parse-zip/local-file-header.js +37 -33
- 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/zip-loader.js +1 -1
- package/dist/esm/{parse-zip → file-provider}/data-view-file.js +1 -0
- package/dist/esm/file-provider/data-view-file.js.map +1 -0
- package/dist/esm/file-provider/file-handle-file.js +57 -0
- package/dist/esm/file-provider/file-handle-file.js.map +1 -0
- package/dist/esm/file-provider/file-handle.js +37 -0
- package/dist/esm/file-provider/file-handle.js.map +1 -0
- package/dist/esm/file-provider/file-provider.js +4 -0
- package/dist/esm/file-provider/file-provider.js.map +1 -0
- package/dist/esm/filesystems/zip-filesystem.js +86 -0
- package/dist/esm/filesystems/zip-filesystem.js.map +1 -0
- package/dist/esm/hash-file-utility.js +14 -0
- package/dist/esm/hash-file-utility.js.map +1 -1
- package/dist/esm/index.js +4 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/parse-zip/cd-file-header.js +24 -15
- package/dist/esm/parse-zip/cd-file-header.js.map +1 -1
- package/dist/esm/parse-zip/end-of-central-directory.js +10 -12
- package/dist/esm/parse-zip/end-of-central-directory.js.map +1 -1
- package/dist/esm/parse-zip/local-file-header.js +16 -15
- 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/zip-loader.js +1 -1
- package/dist/{parse-zip → file-provider}/data-view-file.d.ts +1 -0
- package/dist/file-provider/data-view-file.d.ts.map +1 -0
- package/dist/{parse-zip → file-provider}/data-view-file.js +2 -0
- package/dist/file-provider/file-handle-file.d.ts +53 -0
- package/dist/file-provider/file-handle-file.d.ts.map +1 -0
- package/dist/file-provider/file-handle-file.js +90 -0
- package/dist/file-provider/file-handle.d.ts +40 -0
- package/dist/file-provider/file-handle.d.ts.map +1 -0
- package/dist/file-provider/file-handle.js +57 -0
- package/dist/{parse-zip → file-provider}/file-provider.d.ts +9 -0
- package/dist/file-provider/file-provider.d.ts.map +1 -0
- package/dist/file-provider/file-provider.js +13 -0
- package/dist/filesystems/zip-filesystem.d.ts +44 -0
- package/dist/filesystems/zip-filesystem.d.ts.map +1 -0
- package/dist/filesystems/zip-filesystem.js +119 -0
- package/dist/hash-file-utility.d.ts +7 -0
- package/dist/hash-file-utility.d.ts.map +1 -1
- package/dist/hash-file-utility.js +24 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/parse-zip/cd-file-header.d.ts +6 -1
- package/dist/parse-zip/cd-file-header.d.ts.map +1 -1
- package/dist/parse-zip/cd-file-header.js +29 -16
- 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/end-of-central-directory.js +11 -12
- package/dist/parse-zip/local-file-header.d.ts +3 -1
- package/dist/parse-zip/local-file-header.d.ts.map +1 -1
- package/dist/parse-zip/local-file-header.js +17 -15
- 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/package.json +9 -2
- package/src/{parse-zip → file-provider}/data-view-file.ts +3 -0
- package/src/file-provider/file-handle-file.ts +114 -0
- package/src/file-provider/file-handle.ts +73 -0
- package/src/{parse-zip → file-provider}/file-provider.ts +16 -0
- package/src/filesystems/zip-filesystem.ts +132 -0
- package/src/hash-file-utility.ts +22 -0
- package/src/index.ts +10 -4
- package/src/parse-zip/cd-file-header.ts +33 -25
- package/src/parse-zip/end-of-central-directory.ts +12 -19
- package/src/parse-zip/local-file-header.ts +22 -22
- package/src/parse-zip/search-from-the-end.ts +1 -1
- package/dist/es5/parse-zip/data-view-file.js.map +0 -1
- package/dist/es5/parse-zip/file-provider.js +0 -2
- package/dist/es5/parse-zip/file-provider.js.map +0 -1
- package/dist/esm/parse-zip/data-view-file.js.map +0 -1
- package/dist/esm/parse-zip/file-provider.js +0 -2
- package/dist/esm/parse-zip/file-provider.js.map +0 -1
- package/dist/parse-zip/data-view-file.d.ts.map +0 -1
- package/dist/parse-zip/file-provider.d.ts.map +0 -1
- package/dist/parse-zip/file-provider.js +0 -2
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileHandleFile = void 0;
|
|
4
|
+
const file_handle_1 = require("./file-handle");
|
|
5
|
+
/**
|
|
6
|
+
* Provides file data using node fs library
|
|
7
|
+
*/
|
|
8
|
+
class FileHandleFile {
|
|
9
|
+
/**
|
|
10
|
+
* Returns a new copy of FileHandleFile
|
|
11
|
+
* @param path The path to the file in file system
|
|
12
|
+
*/
|
|
13
|
+
static async from(path) {
|
|
14
|
+
const fileDescriptor = await file_handle_1.FileHandle.open(path);
|
|
15
|
+
return new FileHandleFile(fileDescriptor, fileDescriptor.stat.size);
|
|
16
|
+
}
|
|
17
|
+
constructor(fileDescriptor, size) {
|
|
18
|
+
this.fileDescriptor = fileDescriptor;
|
|
19
|
+
this.size = size;
|
|
20
|
+
}
|
|
21
|
+
/** Close file */
|
|
22
|
+
async destroy() {
|
|
23
|
+
await this.fileDescriptor.close();
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
|
|
27
|
+
* @param offset The offset, in bytes, from the start of the file where to read the data.
|
|
28
|
+
*/
|
|
29
|
+
async getUint8(offset) {
|
|
30
|
+
const val = new Uint8Array((await this.fileDescriptor.read(Buffer.alloc(1), 0, 1, offset)).buffer.buffer).at(0);
|
|
31
|
+
if (val === undefined) {
|
|
32
|
+
throw new Error('something went wrong');
|
|
33
|
+
}
|
|
34
|
+
return val;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Gets an unsigned 16-bit integer at the specified byte offset from the start of the file.
|
|
38
|
+
* @param offset The offset, in bytes, from the start of the file where to read the data.
|
|
39
|
+
*/
|
|
40
|
+
async getUint16(offset) {
|
|
41
|
+
const val = new Uint16Array((await this.fileDescriptor.read(Buffer.alloc(2), 0, 2, offset)).buffer.buffer).at(0);
|
|
42
|
+
if (val === undefined) {
|
|
43
|
+
throw new Error('something went wrong');
|
|
44
|
+
}
|
|
45
|
+
return val;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
|
|
49
|
+
* @param offset The offset, in bytes, from the start of the file where to read the data.
|
|
50
|
+
*/
|
|
51
|
+
async getUint32(offset) {
|
|
52
|
+
const val = new Uint32Array((await this.fileDescriptor.read(Buffer.alloc(4), 0, 4, offset)).buffer.buffer).at(0);
|
|
53
|
+
if (val === undefined) {
|
|
54
|
+
throw new Error('something went wrong');
|
|
55
|
+
}
|
|
56
|
+
return val;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
|
|
60
|
+
* @param offset The offset, in bytes, from the start of the file where to read the data.
|
|
61
|
+
*/
|
|
62
|
+
async getBigUint64(offset) {
|
|
63
|
+
const val = new BigInt64Array((await this.fileDescriptor.read(Buffer.alloc(8), 0, 8, offset)).buffer.buffer).at(0);
|
|
64
|
+
if (val === undefined) {
|
|
65
|
+
throw new Error('something went wrong');
|
|
66
|
+
}
|
|
67
|
+
return val;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
|
|
71
|
+
* @param startOffsset The offset, in byte, from the start of the file where to start reading the data.
|
|
72
|
+
* @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
|
|
73
|
+
*/
|
|
74
|
+
async slice(startOffsset, endOffset) {
|
|
75
|
+
const bigLength = endOffset - startOffsset;
|
|
76
|
+
if (bigLength > Number.MAX_SAFE_INTEGER) {
|
|
77
|
+
throw new Error('too big slice');
|
|
78
|
+
}
|
|
79
|
+
const length = Number(bigLength);
|
|
80
|
+
return (await this.fileDescriptor.read(Buffer.alloc(length), 0, length, startOffsset)).buffer
|
|
81
|
+
.buffer;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* the length (in bytes) of the data.
|
|
85
|
+
*/
|
|
86
|
+
get length() {
|
|
87
|
+
return this.size;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.FileHandleFile = FileHandleFile;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { BigIntStats } from 'fs';
|
|
4
|
+
/** file reading result */
|
|
5
|
+
export type FileReadResult = {
|
|
6
|
+
/** amount of the bytes read */
|
|
7
|
+
bytesRead: number;
|
|
8
|
+
/** the buffer filled with data from file*/
|
|
9
|
+
buffer: Buffer;
|
|
10
|
+
};
|
|
11
|
+
/** Object handling file info */
|
|
12
|
+
export declare class FileHandle {
|
|
13
|
+
private fileDescriptor;
|
|
14
|
+
private stats;
|
|
15
|
+
private constructor();
|
|
16
|
+
/**
|
|
17
|
+
* Opens a `FileHandle`.
|
|
18
|
+
*
|
|
19
|
+
* @param path path to the file
|
|
20
|
+
* @return Fulfills with a {FileHandle} object.
|
|
21
|
+
*/
|
|
22
|
+
static open: (path: string) => Promise<FileHandle>;
|
|
23
|
+
/** Close file */
|
|
24
|
+
close(): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Reads data from the file and stores that in the given buffer.
|
|
27
|
+
*
|
|
28
|
+
* If the file is not modified concurrently, the end-of-file is reached when the
|
|
29
|
+
* number of bytes read is zero.
|
|
30
|
+
* @param buffer A buffer that will be filled with the file data read.
|
|
31
|
+
* @param offset The location in the buffer at which to start filling.
|
|
32
|
+
* @param length The number of bytes to read.
|
|
33
|
+
* @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
|
|
34
|
+
* integer, the current file position will remain unchanged.
|
|
35
|
+
* @return Fulfills upon success with a FileReadResult object
|
|
36
|
+
*/
|
|
37
|
+
read: (buffer: Buffer, offset: number, length: number, position: number | bigint) => Promise<FileReadResult>;
|
|
38
|
+
get stat(): BigIntStats;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=file-handle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-handle.d.ts","sourceRoot":"","sources":["../../src/file-provider/file-handle.ts"],"names":[],"mappings":";;AAAA,OAAO,EAA0B,WAAW,EAAC,MAAM,IAAI,CAAC;AAExD,0BAA0B;AAC1B,MAAM,MAAM,cAAc,GAAG;IAC3B,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,gCAAgC;AAChC,qBAAa,UAAU;IACrB,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO;IAIP;;;;;OAKG;IAEH,MAAM,CAAC,IAAI,SAAgB,MAAM,KAAG,QAAQ,UAAU,CAAC,CAUrD;IAEF,iBAAiB;IACX,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAM5B;;;;;;;;;;;OAWG;IACH,IAAI,WACM,MAAM,UACN,MAAM,UACN,MAAM,YACJ,MAAM,GAAG,MAAM,KACxB,QAAQ,cAAc,CAAC,CAMxB;IAEF,IAAI,IAAI,IAAI,WAAW,CAEtB;CACF"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.FileHandle = void 0;
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
/** Object handling file info */
|
|
7
|
+
class FileHandle {
|
|
8
|
+
constructor(fileDescriptor, stats) {
|
|
9
|
+
/**
|
|
10
|
+
* Reads data from the file and stores that in the given buffer.
|
|
11
|
+
*
|
|
12
|
+
* If the file is not modified concurrently, the end-of-file is reached when the
|
|
13
|
+
* number of bytes read is zero.
|
|
14
|
+
* @param buffer A buffer that will be filled with the file data read.
|
|
15
|
+
* @param offset The location in the buffer at which to start filling.
|
|
16
|
+
* @param length The number of bytes to read.
|
|
17
|
+
* @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
|
|
18
|
+
* integer, the current file position will remain unchanged.
|
|
19
|
+
* @return Fulfills upon success with a FileReadResult object
|
|
20
|
+
*/
|
|
21
|
+
this.read = (buffer, offset, length, position) => {
|
|
22
|
+
return new Promise((s) => {
|
|
23
|
+
(0, fs_1.read)(this.fileDescriptor, buffer, offset, length, position, (_err, bytesRead, buffer) => s({ bytesRead, buffer }));
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
this.fileDescriptor = fileDescriptor;
|
|
27
|
+
this.stats = stats;
|
|
28
|
+
}
|
|
29
|
+
/** Close file */
|
|
30
|
+
async close() {
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
(0, fs_1.close)(this.fileDescriptor, (_err) => resolve());
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
get stat() {
|
|
36
|
+
return this.stats;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.FileHandle = FileHandle;
|
|
40
|
+
_a = FileHandle;
|
|
41
|
+
/**
|
|
42
|
+
* Opens a `FileHandle`.
|
|
43
|
+
*
|
|
44
|
+
* @param path path to the file
|
|
45
|
+
* @return Fulfills with a {FileHandle} object.
|
|
46
|
+
*/
|
|
47
|
+
FileHandle.open = async (path) => {
|
|
48
|
+
const [fd, stats] = await Promise.all([
|
|
49
|
+
new Promise((s) => {
|
|
50
|
+
(0, fs_1.open)(path, undefined, undefined, (_err, fd) => s(fd));
|
|
51
|
+
}),
|
|
52
|
+
new Promise((s) => {
|
|
53
|
+
(0, fs_1.stat)(path, { bigint: true }, (_err, stats) => s(stats));
|
|
54
|
+
})
|
|
55
|
+
]);
|
|
56
|
+
return new FileHandle(fd, stats);
|
|
57
|
+
};
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* Interface for providing file data
|
|
3
3
|
*/
|
|
4
4
|
export interface FileProvider {
|
|
5
|
+
/**
|
|
6
|
+
* Cleanup class data
|
|
7
|
+
*/
|
|
8
|
+
destroy(): Promise<void>;
|
|
5
9
|
/**
|
|
6
10
|
* Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
|
|
7
11
|
* @param offset The offset, in bytes, from the start of the file where to read the data.
|
|
@@ -33,4 +37,9 @@ export interface FileProvider {
|
|
|
33
37
|
*/
|
|
34
38
|
length: bigint;
|
|
35
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Check is the object has FileProvider members
|
|
42
|
+
* @param fileProvider - tested object
|
|
43
|
+
*/
|
|
44
|
+
export declare const isFileProvider: (fileProvider: unknown) => bigint;
|
|
36
45
|
//# sourceMappingURL=file-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-provider.d.ts","sourceRoot":"","sources":["../../src/file-provider/file-provider.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE1C;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3C;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3C;;;OAGG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE9C;;;;OAIG;IACH,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAEpE;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,iBAAkB,OAAO,WAMnD,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isFileProvider = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Check is the object has FileProvider members
|
|
6
|
+
* @param fileProvider - tested object
|
|
7
|
+
*/
|
|
8
|
+
const isFileProvider = (fileProvider) => {
|
|
9
|
+
return (fileProvider?.getUint8 &&
|
|
10
|
+
fileProvider?.slice &&
|
|
11
|
+
fileProvider?.length);
|
|
12
|
+
};
|
|
13
|
+
exports.isFileProvider = isFileProvider;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { FileSystem } from '@loaders.gl/core';
|
|
2
|
+
import { FileProvider } from '../file-provider/file-provider';
|
|
3
|
+
import { ZipCDFileHeader } from '../parse-zip/cd-file-header';
|
|
4
|
+
/**
|
|
5
|
+
* FileSystem adapter for a ZIP file
|
|
6
|
+
* Holds FileProvider object that provides random access to archived files
|
|
7
|
+
*/
|
|
8
|
+
export declare class ZipFileSystem implements FileSystem {
|
|
9
|
+
/** FileProvider instance promise */
|
|
10
|
+
private fileProvider;
|
|
11
|
+
/**
|
|
12
|
+
* Constructor
|
|
13
|
+
* @param file - instance of FileProvider or file path string
|
|
14
|
+
*/
|
|
15
|
+
constructor(file: FileProvider | string);
|
|
16
|
+
/** Clean up resources */
|
|
17
|
+
destroy(): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Get file names list from zip archive
|
|
20
|
+
* @returns array of file names
|
|
21
|
+
*/
|
|
22
|
+
readdir(): Promise<string[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Get file metadata
|
|
25
|
+
* @param filename - name of a file
|
|
26
|
+
* @returns central directory data
|
|
27
|
+
*/
|
|
28
|
+
stat(filename: string): Promise<ZipCDFileHeader & {
|
|
29
|
+
size: number;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Implementation of fetch against this file system
|
|
33
|
+
* @param filename - name of a file
|
|
34
|
+
* @returns - Response with file data
|
|
35
|
+
*/
|
|
36
|
+
fetch(filename: string): Promise<Response>;
|
|
37
|
+
/**
|
|
38
|
+
* Get central directory file header
|
|
39
|
+
* @param filename - name of a file
|
|
40
|
+
* @returns central directory file header
|
|
41
|
+
*/
|
|
42
|
+
private getCDFileHeader;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=zip-filesystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip-filesystem.d.ts","sourceRoot":"","sources":["../../src/filesystems/zip-filesystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAY,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAC,YAAY,EAAiB,MAAM,gCAAgC,CAAC;AAE5E,OAAO,EAAC,eAAe,EAA2B,MAAM,6BAA6B,CAAC;AAUtF;;;GAGG;AACH,qBAAa,aAAc,YAAW,UAAU;IAC9C,oCAAoC;IACpC,OAAO,CAAC,YAAY,CAAuD;IAE3E;;;OAGG;gBACS,IAAI,EAAE,YAAY,GAAG,MAAM;IAavC,yBAAyB;IACnB,OAAO;IAOb;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAalC;;;;OAIG;IACG,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC,CAAC;IAKvE;;;;OAIG;IACG,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IA8BhD;;;;OAIG;YACW,eAAe;CAkB9B"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZipFileSystem = void 0;
|
|
4
|
+
const core_1 = require("@loaders.gl/core");
|
|
5
|
+
const file_provider_1 = require("../file-provider/file-provider");
|
|
6
|
+
const file_handle_file_1 = require("../file-provider/file-handle-file");
|
|
7
|
+
const cd_file_header_1 = require("../parse-zip/cd-file-header");
|
|
8
|
+
const local_file_header_1 = require("../parse-zip/local-file-header");
|
|
9
|
+
/** Handling different compression types in zip */
|
|
10
|
+
const COMPRESSION_METHODS = {
|
|
11
|
+
/** No compression */
|
|
12
|
+
0: async (compressedFile) => compressedFile
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* FileSystem adapter for a ZIP file
|
|
16
|
+
* Holds FileProvider object that provides random access to archived files
|
|
17
|
+
*/
|
|
18
|
+
class ZipFileSystem {
|
|
19
|
+
/**
|
|
20
|
+
* Constructor
|
|
21
|
+
* @param file - instance of FileProvider or file path string
|
|
22
|
+
*/
|
|
23
|
+
constructor(file) {
|
|
24
|
+
/** FileProvider instance promise */
|
|
25
|
+
this.fileProvider = Promise.resolve(null);
|
|
26
|
+
// Try to open file in NodeJS
|
|
27
|
+
if (typeof file === 'string') {
|
|
28
|
+
if (!core_1.isBrowser) {
|
|
29
|
+
this.fileProvider = file_handle_file_1.FileHandleFile.from(file);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new Error('Cannot open file for random access in a WEB browser');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else if ((0, file_provider_1.isFileProvider)(file)) {
|
|
36
|
+
this.fileProvider = Promise.resolve(file);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Clean up resources */
|
|
40
|
+
async destroy() {
|
|
41
|
+
const fileProvider = await this.fileProvider;
|
|
42
|
+
if (fileProvider) {
|
|
43
|
+
fileProvider.destroy();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get file names list from zip archive
|
|
48
|
+
* @returns array of file names
|
|
49
|
+
*/
|
|
50
|
+
async readdir() {
|
|
51
|
+
const fileProvider = await this.fileProvider;
|
|
52
|
+
if (!fileProvider) {
|
|
53
|
+
throw new Error('No data detected in the zip archive');
|
|
54
|
+
}
|
|
55
|
+
const fileNames = [];
|
|
56
|
+
const zipCDIterator = (0, cd_file_header_1.zipCDFileHeaderGenerator)(fileProvider);
|
|
57
|
+
for await (const cdHeader of zipCDIterator) {
|
|
58
|
+
fileNames.push(cdHeader.fileName);
|
|
59
|
+
}
|
|
60
|
+
return fileNames;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get file metadata
|
|
64
|
+
* @param filename - name of a file
|
|
65
|
+
* @returns central directory data
|
|
66
|
+
*/
|
|
67
|
+
async stat(filename) {
|
|
68
|
+
const cdFileHeader = await this.getCDFileHeader(filename);
|
|
69
|
+
return { ...cdFileHeader, size: Number(cdFileHeader.uncompressedSize) };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Implementation of fetch against this file system
|
|
73
|
+
* @param filename - name of a file
|
|
74
|
+
* @returns - Response with file data
|
|
75
|
+
*/
|
|
76
|
+
async fetch(filename) {
|
|
77
|
+
const fileProvider = await this.fileProvider;
|
|
78
|
+
if (!fileProvider) {
|
|
79
|
+
throw new Error('No data detected in the zip archive');
|
|
80
|
+
}
|
|
81
|
+
const cdFileHeader = await this.getCDFileHeader(filename);
|
|
82
|
+
const localFileHeader = await (0, local_file_header_1.parseZipLocalFileHeader)(cdFileHeader.localHeaderOffset, fileProvider);
|
|
83
|
+
if (!localFileHeader) {
|
|
84
|
+
throw new Error('Local file header has not been found in the zip archive`');
|
|
85
|
+
}
|
|
86
|
+
const compressionHandler = COMPRESSION_METHODS[localFileHeader.compressionMethod.toString()];
|
|
87
|
+
if (!compressionHandler) {
|
|
88
|
+
throw Error('Only Deflation compression is supported');
|
|
89
|
+
}
|
|
90
|
+
const compressedFile = await fileProvider.slice(localFileHeader.fileDataOffset, localFileHeader.fileDataOffset + localFileHeader.compressedSize);
|
|
91
|
+
const uncompressedFile = await compressionHandler(compressedFile);
|
|
92
|
+
const response = new Response(uncompressedFile);
|
|
93
|
+
return response;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get central directory file header
|
|
97
|
+
* @param filename - name of a file
|
|
98
|
+
* @returns central directory file header
|
|
99
|
+
*/
|
|
100
|
+
async getCDFileHeader(filename) {
|
|
101
|
+
const fileProvider = await this.fileProvider;
|
|
102
|
+
if (!fileProvider) {
|
|
103
|
+
throw new Error('No data detected in the zip archive');
|
|
104
|
+
}
|
|
105
|
+
const zipCDIterator = (0, cd_file_header_1.zipCDFileHeaderGenerator)(fileProvider);
|
|
106
|
+
let result = null;
|
|
107
|
+
for await (const cdHeader of zipCDIterator) {
|
|
108
|
+
if (cdHeader.fileName === filename) {
|
|
109
|
+
result = cdHeader;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!result) {
|
|
114
|
+
throw new Error('File has not been found in the zip archive');
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.ZipFileSystem = ZipFileSystem;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { FileProvider } from './file-provider/file-provider';
|
|
2
3
|
/** Element of hash array */
|
|
3
4
|
export type HashElement = {
|
|
4
5
|
/** File name hash */
|
|
@@ -25,4 +26,10 @@ export declare const parseHashFile: (hashFile: ArrayBuffer) => HashElement[];
|
|
|
25
26
|
* @returns required hash element or undefined if not found
|
|
26
27
|
*/
|
|
27
28
|
export declare const findBin: (hashToSearch: Buffer, hashArray: HashElement[]) => HashElement | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* generates hash info from central directory
|
|
31
|
+
* @param fileProvider - provider of the archive
|
|
32
|
+
* @returns ready to use hash info
|
|
33
|
+
*/
|
|
34
|
+
export declare const generateHashInfo: (fileProvider: FileProvider) => Promise<HashElement[]>;
|
|
28
35
|
//# sourceMappingURL=hash-file-utility.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash-file-utility.d.ts","sourceRoot":"","sources":["../src/hash-file-utility.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"hash-file-utility.d.ts","sourceRoot":"","sources":["../src/hash-file-utility.ts"],"names":[],"mappings":";AAEA,OAAO,EAAC,YAAY,EAAC,MAAM,+BAA+B,CAAC;AAE3D,4BAA4B;AAC5B,MAAM,MAAM,WAAW,GAAG;IACxB,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,SAAS,MAAM,KAAG,MAY5D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,aAAc,WAAW,KAAG,WAAW,EAmBhE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,OAAO,iBACJ,MAAM,aACT,WAAW,EAAE,KACvB,WAAW,GAAG,SAgBhB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,iBAAwB,YAAY,KAAG,QAAQ,WAAW,EAAE,CAWxF,CAAC"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findBin = exports.parseHashFile = exports.compareHashes = void 0;
|
|
6
|
+
exports.generateHashInfo = exports.findBin = exports.parseHashFile = exports.compareHashes = void 0;
|
|
7
|
+
const md5_1 = __importDefault(require("md5"));
|
|
8
|
+
const cd_file_header_1 = require("./parse-zip/cd-file-header");
|
|
4
9
|
/**
|
|
5
10
|
* Comparing md5 hashes according to https://github.com/Esri/i3s-spec/blob/master/docs/2.0/slpk_hashtable.pcsl.md step 5
|
|
6
11
|
* @param hash1 hash to compare
|
|
@@ -63,3 +68,21 @@ const findBin = (hashToSearch, hashArray) => {
|
|
|
63
68
|
return undefined;
|
|
64
69
|
};
|
|
65
70
|
exports.findBin = findBin;
|
|
71
|
+
/**
|
|
72
|
+
* generates hash info from central directory
|
|
73
|
+
* @param fileProvider - provider of the archive
|
|
74
|
+
* @returns ready to use hash info
|
|
75
|
+
*/
|
|
76
|
+
const generateHashInfo = async (fileProvider) => {
|
|
77
|
+
const zipCDIterator = (0, cd_file_header_1.zipCDFileHeaderGenerator)(fileProvider);
|
|
78
|
+
const hashInfo = [];
|
|
79
|
+
for await (const cdHeader of zipCDIterator) {
|
|
80
|
+
hashInfo.push({
|
|
81
|
+
hash: Buffer.from((0, md5_1.default)(cdHeader.fileName.split('\\').join('/').toLocaleLowerCase()), 'hex'),
|
|
82
|
+
offset: cdHeader.localHeaderOffset
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
hashInfo.sort((a, b) => (0, exports.compareHashes)(a.hash, b.hash));
|
|
86
|
+
return hashInfo;
|
|
87
|
+
};
|
|
88
|
+
exports.generateHashInfo = generateHashInfo;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
export { ZipLoader } from './zip-loader';
|
|
2
2
|
export { ZipWriter } from './zip-writer';
|
|
3
3
|
export { default as TarBuilder } from './tar-builder';
|
|
4
|
-
export type { FileProvider } from './
|
|
5
|
-
export {
|
|
4
|
+
export type { FileProvider } from './file-provider/file-provider';
|
|
5
|
+
export { FileHandleFile } from './file-provider/file-handle-file';
|
|
6
|
+
export { DataViewFile } from './file-provider/data-view-file';
|
|
7
|
+
export { parseZipCDFileHeader, zipCDFileHeaderGenerator, signature as cdSignature } from './parse-zip/cd-file-header';
|
|
6
8
|
export { parseZipLocalFileHeader, signature as localHeaderSignature } from './parse-zip/local-file-header';
|
|
7
9
|
export { parseEoCDRecord } from './parse-zip/end-of-central-directory';
|
|
8
10
|
export { searchFromTheEnd } from './parse-zip/search-from-the-end';
|
|
9
|
-
export { DataViewFile } from './parse-zip/data-view-file';
|
|
10
11
|
export type { HashElement } from './hash-file-utility';
|
|
11
|
-
export { compareHashes, parseHashFile, findBin } from './hash-file-utility';
|
|
12
|
+
export { compareHashes, parseHashFile, findBin, generateHashInfo } from './hash-file-utility';
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AACvC,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AACvC,OAAO,EAAC,OAAO,IAAI,UAAU,EAAC,MAAM,eAAe,CAAC;AAEpD,YAAY,EAAC,YAAY,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AACvC,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AACvC,OAAO,EAAC,OAAO,IAAI,UAAU,EAAC,MAAM,eAAe,CAAC;AAEpD,YAAY,EAAC,YAAY,EAAC,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAC,cAAc,EAAC,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAC,YAAY,EAAC,MAAM,gCAAgC,CAAC;AAE5D,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,SAAS,IAAI,WAAW,EACzB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,uBAAuB,EACvB,SAAS,IAAI,oBAAoB,EAClC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAC,eAAe,EAAC,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAC,gBAAgB,EAAC,MAAM,iCAAiC,CAAC;AAEjE,YAAY,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAC,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,gBAAgB,EAAC,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,15 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.generateHashInfo = exports.findBin = exports.parseHashFile = exports.compareHashes = exports.searchFromTheEnd = exports.parseEoCDRecord = exports.localHeaderSignature = exports.parseZipLocalFileHeader = exports.cdSignature = exports.zipCDFileHeaderGenerator = exports.parseZipCDFileHeader = exports.DataViewFile = exports.FileHandleFile = exports.TarBuilder = exports.ZipWriter = exports.ZipLoader = void 0;
|
|
7
7
|
var zip_loader_1 = require("./zip-loader");
|
|
8
8
|
Object.defineProperty(exports, "ZipLoader", { enumerable: true, get: function () { return zip_loader_1.ZipLoader; } });
|
|
9
9
|
var zip_writer_1 = require("./zip-writer");
|
|
10
10
|
Object.defineProperty(exports, "ZipWriter", { enumerable: true, get: function () { return zip_writer_1.ZipWriter; } });
|
|
11
11
|
var tar_builder_1 = require("./tar-builder");
|
|
12
12
|
Object.defineProperty(exports, "TarBuilder", { enumerable: true, get: function () { return __importDefault(tar_builder_1).default; } });
|
|
13
|
+
var file_handle_file_1 = require("./file-provider/file-handle-file");
|
|
14
|
+
Object.defineProperty(exports, "FileHandleFile", { enumerable: true, get: function () { return file_handle_file_1.FileHandleFile; } });
|
|
15
|
+
var data_view_file_1 = require("./file-provider/data-view-file");
|
|
16
|
+
Object.defineProperty(exports, "DataViewFile", { enumerable: true, get: function () { return data_view_file_1.DataViewFile; } });
|
|
13
17
|
var cd_file_header_1 = require("./parse-zip/cd-file-header");
|
|
14
18
|
Object.defineProperty(exports, "parseZipCDFileHeader", { enumerable: true, get: function () { return cd_file_header_1.parseZipCDFileHeader; } });
|
|
19
|
+
Object.defineProperty(exports, "zipCDFileHeaderGenerator", { enumerable: true, get: function () { return cd_file_header_1.zipCDFileHeaderGenerator; } });
|
|
15
20
|
Object.defineProperty(exports, "cdSignature", { enumerable: true, get: function () { return cd_file_header_1.signature; } });
|
|
16
21
|
var local_file_header_1 = require("./parse-zip/local-file-header");
|
|
17
22
|
Object.defineProperty(exports, "parseZipLocalFileHeader", { enumerable: true, get: function () { return local_file_header_1.parseZipLocalFileHeader; } });
|
|
@@ -20,9 +25,8 @@ var end_of_central_directory_1 = require("./parse-zip/end-of-central-directory")
|
|
|
20
25
|
Object.defineProperty(exports, "parseEoCDRecord", { enumerable: true, get: function () { return end_of_central_directory_1.parseEoCDRecord; } });
|
|
21
26
|
var search_from_the_end_1 = require("./parse-zip/search-from-the-end");
|
|
22
27
|
Object.defineProperty(exports, "searchFromTheEnd", { enumerable: true, get: function () { return search_from_the_end_1.searchFromTheEnd; } });
|
|
23
|
-
var data_view_file_1 = require("./parse-zip/data-view-file");
|
|
24
|
-
Object.defineProperty(exports, "DataViewFile", { enumerable: true, get: function () { return data_view_file_1.DataViewFile; } });
|
|
25
28
|
var hash_file_utility_1 = require("./hash-file-utility");
|
|
26
29
|
Object.defineProperty(exports, "compareHashes", { enumerable: true, get: function () { return hash_file_utility_1.compareHashes; } });
|
|
27
30
|
Object.defineProperty(exports, "parseHashFile", { enumerable: true, get: function () { return hash_file_utility_1.parseHashFile; } });
|
|
28
31
|
Object.defineProperty(exports, "findBin", { enumerable: true, get: function () { return hash_file_utility_1.findBin; } });
|
|
32
|
+
Object.defineProperty(exports, "generateHashInfo", { enumerable: true, get: function () { return hash_file_utility_1.generateHashInfo; } });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FileProvider } from '
|
|
1
|
+
import { FileProvider } from '../file-provider/file-provider';
|
|
2
2
|
import { ZipSignature } from './search-from-the-end';
|
|
3
3
|
/**
|
|
4
4
|
* zip central directory file header info
|
|
@@ -28,4 +28,9 @@ export declare const signature: ZipSignature;
|
|
|
28
28
|
* @returns Info from the header
|
|
29
29
|
*/
|
|
30
30
|
export declare const parseZipCDFileHeader: (headerOffset: bigint, buffer: FileProvider) => Promise<ZipCDFileHeader | null>;
|
|
31
|
+
/**
|
|
32
|
+
* Create iterator over files of zip archive
|
|
33
|
+
* @param fileProvider - file provider that provider random access to the file
|
|
34
|
+
*/
|
|
35
|
+
export declare function zipCDFileHeaderGenerator(fileProvider: FileProvider): AsyncGenerator<ZipCDFileHeader, void, unknown>;
|
|
31
36
|
//# sourceMappingURL=cd-file-header.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cd-file-header.d.ts","sourceRoot":"","sources":["../../src/parse-zip/cd-file-header.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"cd-file-header.d.ts","sourceRoot":"","sources":["../../src/parse-zip/cd-file-header.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,gCAAgC,CAAC;AAE5D,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,sBAAsB;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,wBAAwB;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,uBAAuB;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,uBAAuB;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,yBAAyB;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAUF,eAAO,MAAM,SAAS,EAAE,YAAuC,CAAC;AAEhE;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,iBACjB,MAAM,UACZ,YAAY,KACnB,QAAQ,eAAe,GAAG,IAAI,CAqDhC,CAAC;AAEF;;;GAGG;AACH,wBAAuB,wBAAwB,CAAC,YAAY,EAAE,YAAY,kDAUzE"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseZipCDFileHeader = exports.signature = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
exports.zipCDFileHeaderGenerator = exports.parseZipCDFileHeader = exports.signature = void 0;
|
|
4
|
+
const end_of_central_directory_1 = require("./end-of-central-directory");
|
|
5
|
+
// offsets accroding to https://en.wikipedia.org/wiki/ZIP_(file_format)
|
|
6
|
+
const CD_COMPRESSED_SIZE_OFFSET = 20n;
|
|
7
|
+
const CD_UNCOMPRESSED_SIZE_OFFSET = 24n;
|
|
8
|
+
const CD_FILE_NAME_LENGTH_OFFSET = 28n;
|
|
9
|
+
const CD_EXTRA_FIELD_LENGTH_OFFSET = 30n;
|
|
10
|
+
const CD_LOCAL_HEADER_OFFSET_OFFSET = 42n;
|
|
11
|
+
const CD_FILE_NAME_OFFSET = 46n;
|
|
12
12
|
exports.signature = [0x50, 0x4b, 0x01, 0x02];
|
|
13
13
|
/**
|
|
14
14
|
* Parses central directory file header of zip file
|
|
@@ -20,13 +20,13 @@ const parseZipCDFileHeader = async (headerOffset, buffer) => {
|
|
|
20
20
|
if (Buffer.from(await buffer.slice(headerOffset, headerOffset + 4n)).compare(Buffer.from(exports.signature)) !== 0) {
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
|
-
let compressedSize = BigInt(await buffer.getUint32(headerOffset +
|
|
24
|
-
let uncompressedSize = BigInt(await buffer.getUint32(headerOffset +
|
|
25
|
-
const extraFieldLength = await buffer.getUint16(headerOffset +
|
|
26
|
-
const fileNameLength = await buffer.getUint16(headerOffset +
|
|
27
|
-
const fileName = new TextDecoder().decode(await buffer.slice(headerOffset +
|
|
28
|
-
const extraOffset = headerOffset +
|
|
29
|
-
const oldFormatOffset = await buffer.getUint32(headerOffset +
|
|
23
|
+
let compressedSize = BigInt(await buffer.getUint32(headerOffset + CD_COMPRESSED_SIZE_OFFSET));
|
|
24
|
+
let uncompressedSize = BigInt(await buffer.getUint32(headerOffset + CD_UNCOMPRESSED_SIZE_OFFSET));
|
|
25
|
+
const extraFieldLength = await buffer.getUint16(headerOffset + CD_EXTRA_FIELD_LENGTH_OFFSET);
|
|
26
|
+
const fileNameLength = await buffer.getUint16(headerOffset + CD_FILE_NAME_LENGTH_OFFSET);
|
|
27
|
+
const fileName = new TextDecoder().decode(await buffer.slice(headerOffset + CD_FILE_NAME_OFFSET, headerOffset + CD_FILE_NAME_OFFSET + BigInt(fileNameLength)));
|
|
28
|
+
const extraOffset = headerOffset + CD_FILE_NAME_OFFSET + BigInt(fileNameLength);
|
|
29
|
+
const oldFormatOffset = await buffer.getUint32(headerOffset + CD_LOCAL_HEADER_OFFSET_OFFSET);
|
|
30
30
|
let fileDataOffset = BigInt(oldFormatOffset);
|
|
31
31
|
let offsetInZip64Data = 4n;
|
|
32
32
|
// looking for info that might be also be in zip64 extra field
|
|
@@ -53,3 +53,16 @@ const parseZipCDFileHeader = async (headerOffset, buffer) => {
|
|
|
53
53
|
};
|
|
54
54
|
};
|
|
55
55
|
exports.parseZipCDFileHeader = parseZipCDFileHeader;
|
|
56
|
+
/**
|
|
57
|
+
* Create iterator over files of zip archive
|
|
58
|
+
* @param fileProvider - file provider that provider random access to the file
|
|
59
|
+
*/
|
|
60
|
+
async function* zipCDFileHeaderGenerator(fileProvider) {
|
|
61
|
+
const { cdStartOffset } = await (0, end_of_central_directory_1.parseEoCDRecord)(fileProvider);
|
|
62
|
+
let cdHeader = await (0, exports.parseZipCDFileHeader)(cdStartOffset, fileProvider);
|
|
63
|
+
while (cdHeader) {
|
|
64
|
+
yield cdHeader;
|
|
65
|
+
cdHeader = await (0, exports.parseZipCDFileHeader)(cdHeader.extraOffset + BigInt(cdHeader.extraFieldLength), fileProvider);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.zipCDFileHeaderGenerator = zipCDFileHeaderGenerator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"end-of-central-directory.d.ts","sourceRoot":"","sources":["../../src/parse-zip/end-of-central-directory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"end-of-central-directory.d.ts","sourceRoot":"","sources":["../../src/parse-zip/end-of-central-directory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,gCAAgC,CAAC;AAG5D;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,2CAA2C;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,2CAA2C;IAC3C,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAaF;;;;GAIG;AACH,eAAO,MAAM,eAAe,iBAAwB,YAAY,KAAG,QAAQ,aAAa,CAwCvF,CAAC"}
|