@loaders.gl/tile-converter 4.0.0-alpha.20 → 4.0.0-alpha.22
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/converter.min.js +113 -113
- package/dist/dist.min.js +33160 -32581
- package/dist/es5/deps-installer/deps-installer.js +1 -1
- package/dist/es5/i3s-converter/helpers/load-3d-tiles.js +70 -4
- package/dist/es5/i3s-converter/helpers/load-3d-tiles.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +34 -32
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/i3s-server/controllers/slpk-controller.js +2 -2
- package/dist/es5/i3s-server/controllers/slpk-controller.js.map +1 -1
- package/dist/es5/index.js +0 -7
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/pgm-loader.js +1 -1
- package/dist/es5/slpk-extractor/slpk-extractor.js +7 -8
- package/dist/es5/slpk-extractor/slpk-extractor.js.map +1 -1
- package/dist/esm/deps-installer/deps-installer.js +1 -1
- package/dist/esm/i3s-converter/helpers/load-3d-tiles.js +33 -4
- package/dist/esm/i3s-converter/helpers/load-3d-tiles.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js +7 -5
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/i3s-server/bin/i3s-server.min.js +70 -70
- package/dist/esm/i3s-server/controllers/slpk-controller.js +1 -1
- package/dist/esm/i3s-server/controllers/slpk-controller.js.map +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/pgm-loader.js +1 -1
- package/dist/esm/slpk-extractor/slpk-extractor.js +2 -3
- package/dist/esm/slpk-extractor/slpk-extractor.js.map +1 -1
- package/dist/i3s-converter/helpers/load-3d-tiles.d.ts +15 -0
- package/dist/i3s-converter/helpers/load-3d-tiles.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/load-3d-tiles.js +51 -5
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.js +6 -4
- package/dist/i3s-server/controllers/slpk-controller.js +2 -2
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/slpk-extractor/slpk-extractor.d.ts +1 -1
- package/dist/slpk-extractor/slpk-extractor.d.ts.map +1 -1
- package/dist/slpk-extractor/slpk-extractor.js +3 -4
- package/dist/slpk-extractor.min.js +35 -35
- package/package.json +14 -14
- package/src/i3s-converter/helpers/load-3d-tiles.ts +61 -5
- package/src/i3s-converter/i3s-converter.ts +12 -5
- package/src/i3s-server/controllers/slpk-controller.ts +1 -1
- package/src/index.ts +0 -1
- package/src/slpk-extractor/slpk-extractor.ts +2 -3
- package/dist/es5/slpk-extractor/helpers/file-handle-file.js +0 -214
- package/dist/es5/slpk-extractor/helpers/file-handle-file.js.map +0 -1
- package/dist/es5/slpk-extractor/helpers/fs-promises.js +0 -77
- package/dist/es5/slpk-extractor/helpers/fs-promises.js.map +0 -1
- package/dist/esm/slpk-extractor/helpers/file-handle-file.js +0 -54
- package/dist/esm/slpk-extractor/helpers/file-handle-file.js.map +0 -1
- package/dist/esm/slpk-extractor/helpers/fs-promises.js +0 -32
- package/dist/esm/slpk-extractor/helpers/fs-promises.js.map +0 -1
- package/dist/slpk-extractor/helpers/file-handle-file.d.ts +0 -51
- package/dist/slpk-extractor/helpers/file-handle-file.d.ts.map +0 -1
- package/dist/slpk-extractor/helpers/file-handle-file.js +0 -86
- package/dist/slpk-extractor/helpers/fs-promises.d.ts +0 -38
- package/dist/slpk-extractor/helpers/fs-promises.d.ts.map +0 -1
- package/dist/slpk-extractor/helpers/fs-promises.js +0 -51
- package/src/slpk-extractor/helpers/file-handle-file.ts +0 -109
- package/src/slpk-extractor/helpers/fs-promises.ts +0 -66
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fs-promises.js","names":["read","open","stat","FileHandle","constructor","fileDescriptor","stats","_defineProperty","buffer","offset","length","position","Promise","s","_err","bytesRead","path","fd","all","undefined","bigint"],"sources":["../../../../src/slpk-extractor/helpers/fs-promises.ts"],"sourcesContent":["import {read, open, stat, BigIntStats} from 'fs';\n\n/** file reading result */\nexport type FileReadResult = {\n /** amount of the bytes read */\n bytesRead: number;\n /** the buffer filled with data from file*/\n buffer: Buffer;\n};\n\n/** Object handling file info */\nexport class FileHandle {\n private fileDescriptor: number;\n private stats: BigIntStats;\n private constructor(fileDescriptor: number, stats: BigIntStats) {\n this.fileDescriptor = fileDescriptor;\n this.stats = stats;\n }\n /**\n * Opens a `FileHandle`.\n *\n * @param path path to the file\n * @return Fulfills with a {FileHandle} object.\n */\n\n static open = async (path: string): Promise<FileHandle> => {\n const [fd, stats] = await Promise.all([\n new Promise<number>((s) => {\n open(path, undefined, undefined, (_err, fd) => s(fd));\n }),\n new Promise<BigIntStats>((s) => {\n stat(path, {bigint: true}, (_err, stats) => s(stats));\n })\n ]);\n return new FileHandle(fd, stats);\n };\n\n /**\n * Reads data from the file and stores that in the given buffer.\n *\n * If the file is not modified concurrently, the end-of-file is reached when the\n * number of bytes read is zero.\n * @param buffer A buffer that will be filled with the file data read.\n * @param offset The location in the buffer at which to start filling.\n * @param length The number of bytes to read.\n * @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\n * integer, the current file position will remain unchanged.\n * @return Fulfills upon success with a FileReadResult object\n */\n read = (\n buffer: Buffer,\n offset: number,\n length: number,\n position: number | bigint\n ): Promise<FileReadResult> => {\n return new Promise((s) => {\n read(this.fileDescriptor, buffer, offset, length, position, (_err, bytesRead, buffer) =>\n s({bytesRead, buffer})\n );\n });\n };\n\n get stat(): BigIntStats {\n return this.stats;\n }\n}\n"],"mappings":";AAAA,SAAQA,IAAI,EAAEC,IAAI,EAAEC,IAAI,QAAoB,IAAI;AAWhD,OAAO,MAAMC,UAAU,CAAC;EAGdC,WAAWA,CAACC,cAAsB,EAAEC,KAAkB,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA,eAmCzD,CACLC,MAAc,EACdC,MAAc,EACdC,MAAc,EACdC,QAAyB,KACG;MAC5B,OAAO,IAAIC,OAAO,CAAEC,CAAC,IAAK;QACxBb,IAAI,CAAC,IAAI,CAACK,cAAc,EAAEG,MAAM,EAAEC,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAE,CAACG,IAAI,EAAEC,SAAS,EAAEP,MAAM,KAClFK,CAAC,CAAC;UAACE,SAAS;UAAEP;QAAM,CAAC,CACvB,CAAC;MACH,CAAC,CAAC;IACJ,CAAC;IA7CC,IAAI,CAACH,cAAc,GAAGA,cAAc;IACpC,IAAI,CAACC,KAAK,GAAGA,KAAK;EACpB;EA6CA,IAAIJ,IAAIA,CAAA,EAAgB;IACtB,OAAO,IAAI,CAACI,KAAK;EACnB;AACF;AAACC,eAAA,CAtDYJ,UAAU,UAcP,MAAOa,IAAY,IAA0B;EACzD,MAAM,CAACC,EAAE,EAAEX,KAAK,CAAC,GAAG,MAAMM,OAAO,CAACM,GAAG,CAAC,CACpC,IAAIN,OAAO,CAAUC,CAAC,IAAK;IACzBZ,IAAI,CAACe,IAAI,EAAEG,SAAS,EAAEA,SAAS,EAAE,CAACL,IAAI,EAAEG,EAAE,KAAKJ,CAAC,CAACI,EAAE,CAAC,CAAC;EACvD,CAAC,CAAC,EACF,IAAIL,OAAO,CAAeC,CAAC,IAAK;IAC9BX,IAAI,CAACc,IAAI,EAAE;MAACI,MAAM,EAAE;IAAI,CAAC,EAAE,CAACN,IAAI,EAAER,KAAK,KAAKO,CAAC,CAACP,KAAK,CAAC,CAAC;EACvD,CAAC,CAAC,CACH,CAAC;EACF,OAAO,IAAIH,UAAU,CAACc,EAAE,EAAEX,KAAK,CAAC;AAClC,CAAC"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { FileProvider } from '@loaders.gl/zip';
|
|
2
|
-
/**
|
|
3
|
-
* Provides file data using node fs library
|
|
4
|
-
*/
|
|
5
|
-
export declare class FileHandleFile implements FileProvider {
|
|
6
|
-
/**
|
|
7
|
-
* Returns a new copy of FileHandleFile
|
|
8
|
-
* @param path The path to the file in file system
|
|
9
|
-
*/
|
|
10
|
-
static from(path: string): Promise<FileHandleFile>;
|
|
11
|
-
/**
|
|
12
|
-
* The FileHandle from which data is provided
|
|
13
|
-
*/
|
|
14
|
-
private fileDescriptor;
|
|
15
|
-
/**
|
|
16
|
-
* The file length in bytes
|
|
17
|
-
*/
|
|
18
|
-
private size;
|
|
19
|
-
private constructor();
|
|
20
|
-
/**
|
|
21
|
-
* Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
|
|
22
|
-
* @param offset The offset, in bytes, from the start of the file where to read the data.
|
|
23
|
-
*/
|
|
24
|
-
getUint8(offset: bigint): Promise<number>;
|
|
25
|
-
/**
|
|
26
|
-
* Gets an unsigned 16-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
|
-
getUint16(offset: bigint): Promise<number>;
|
|
30
|
-
/**
|
|
31
|
-
* Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
|
|
32
|
-
* @param offset The offset, in bytes, from the start of the file where to read the data.
|
|
33
|
-
*/
|
|
34
|
-
getUint32(offset: bigint): Promise<number>;
|
|
35
|
-
/**
|
|
36
|
-
* Gets an unsigned 32-bit integer 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
|
-
getBigUint64(offset: bigint): Promise<bigint>;
|
|
40
|
-
/**
|
|
41
|
-
* returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
|
|
42
|
-
* @param startOffsset The offset, in byte, from the start of the file where to start reading the data.
|
|
43
|
-
* @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
|
|
44
|
-
*/
|
|
45
|
-
slice(startOffsset: bigint, endOffset: bigint): Promise<ArrayBuffer>;
|
|
46
|
-
/**
|
|
47
|
-
* the length (in bytes) of the data.
|
|
48
|
-
*/
|
|
49
|
-
get length(): bigint;
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=file-handle-file.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-handle-file.d.ts","sourceRoot":"","sources":["../../../src/slpk-extractor/helpers/file-handle-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAG7C;;GAEG;AACH,qBAAa,cAAe,YAAW,YAAY;IACjD;;;OAGG;WACU,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAKxD;;OAEG;IACH,OAAO,CAAC,cAAc,CAAa;IAEnC;;OAEG;IACH,OAAO,CAAC,IAAI,CAAS;IAErB,OAAO;IAKP;;;OAGG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAU/C;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAUhD;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAUhD;;;OAGG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAUnD;;;;OAIG;IACG,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAU1E;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;CACF"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FileHandleFile = void 0;
|
|
4
|
-
const fs_promises_1 = require("./fs-promises");
|
|
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 fs_promises_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
|
-
/**
|
|
22
|
-
* Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
|
|
23
|
-
* @param offset The offset, in bytes, from the start of the file where to read the data.
|
|
24
|
-
*/
|
|
25
|
-
async getUint8(offset) {
|
|
26
|
-
const val = new Uint8Array((await this.fileDescriptor.read(Buffer.alloc(1), 0, 1, offset)).buffer.buffer).at(0);
|
|
27
|
-
if (val === undefined) {
|
|
28
|
-
throw new Error('something went wrong');
|
|
29
|
-
}
|
|
30
|
-
return val;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Gets an unsigned 16-bit integer at the specified byte offset from the start of the file.
|
|
34
|
-
* @param offset The offset, in bytes, from the start of the file where to read the data.
|
|
35
|
-
*/
|
|
36
|
-
async getUint16(offset) {
|
|
37
|
-
const val = new Uint16Array((await this.fileDescriptor.read(Buffer.alloc(2), 0, 2, offset)).buffer.buffer).at(0);
|
|
38
|
-
if (val === undefined) {
|
|
39
|
-
throw new Error('something went wrong');
|
|
40
|
-
}
|
|
41
|
-
return val;
|
|
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) {
|
|
48
|
-
const val = new Uint32Array((await this.fileDescriptor.read(Buffer.alloc(4), 0, 4, offset)).buffer.buffer).at(0);
|
|
49
|
-
if (val === undefined) {
|
|
50
|
-
throw new Error('something went wrong');
|
|
51
|
-
}
|
|
52
|
-
return val;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
|
|
56
|
-
* @param offset The offset, in bytes, from the start of the file where to read the data.
|
|
57
|
-
*/
|
|
58
|
-
async getBigUint64(offset) {
|
|
59
|
-
const val = new BigInt64Array((await this.fileDescriptor.read(Buffer.alloc(8), 0, 8, offset)).buffer.buffer).at(0);
|
|
60
|
-
if (val === undefined) {
|
|
61
|
-
throw new Error('something went wrong');
|
|
62
|
-
}
|
|
63
|
-
return val;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
|
|
67
|
-
* @param startOffsset The offset, in byte, from the start of the file where to start reading the data.
|
|
68
|
-
* @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
|
|
69
|
-
*/
|
|
70
|
-
async slice(startOffsset, endOffset) {
|
|
71
|
-
const bigLength = endOffset - startOffsset;
|
|
72
|
-
if (bigLength > Number.MAX_SAFE_INTEGER) {
|
|
73
|
-
throw new Error('too big slice');
|
|
74
|
-
}
|
|
75
|
-
const length = Number(bigLength);
|
|
76
|
-
return (await this.fileDescriptor.read(Buffer.alloc(length), 0, length, startOffsset)).buffer
|
|
77
|
-
.buffer;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* the length (in bytes) of the data.
|
|
81
|
-
*/
|
|
82
|
-
get length() {
|
|
83
|
-
return this.size;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
exports.FileHandleFile = FileHandleFile;
|
|
@@ -1,38 +0,0 @@
|
|
|
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
|
-
/**
|
|
24
|
-
* Reads data from the file and stores that in the given buffer.
|
|
25
|
-
*
|
|
26
|
-
* If the file is not modified concurrently, the end-of-file is reached when the
|
|
27
|
-
* number of bytes read is zero.
|
|
28
|
-
* @param buffer A buffer that will be filled with the file data read.
|
|
29
|
-
* @param offset The location in the buffer at which to start filling.
|
|
30
|
-
* @param length The number of bytes to read.
|
|
31
|
-
* @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
|
|
32
|
-
* integer, the current file position will remain unchanged.
|
|
33
|
-
* @return Fulfills upon success with a FileReadResult object
|
|
34
|
-
*/
|
|
35
|
-
read: (buffer: Buffer, offset: number, length: number, position: number | bigint) => Promise<FileReadResult>;
|
|
36
|
-
get stat(): BigIntStats;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=fs-promises.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fs-promises.d.ts","sourceRoot":"","sources":["../../../src/slpk-extractor/helpers/fs-promises.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAmB,WAAW,EAAC,MAAM,IAAI,CAAC;AAEjD,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;;;;;;;;;;;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"}
|
|
@@ -1,51 +0,0 @@
|
|
|
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
|
-
get stat() {
|
|
30
|
-
return this.stats;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.FileHandle = FileHandle;
|
|
34
|
-
_a = FileHandle;
|
|
35
|
-
/**
|
|
36
|
-
* Opens a `FileHandle`.
|
|
37
|
-
*
|
|
38
|
-
* @param path path to the file
|
|
39
|
-
* @return Fulfills with a {FileHandle} object.
|
|
40
|
-
*/
|
|
41
|
-
FileHandle.open = async (path) => {
|
|
42
|
-
const [fd, stats] = await Promise.all([
|
|
43
|
-
new Promise((s) => {
|
|
44
|
-
(0, fs_1.open)(path, undefined, undefined, (_err, fd) => s(fd));
|
|
45
|
-
}),
|
|
46
|
-
new Promise((s) => {
|
|
47
|
-
(0, fs_1.stat)(path, { bigint: true }, (_err, stats) => s(stats));
|
|
48
|
-
})
|
|
49
|
-
]);
|
|
50
|
-
return new FileHandle(fd, stats);
|
|
51
|
-
};
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import {FileProvider} from '@loaders.gl/zip';
|
|
2
|
-
import {FileHandle} from './fs-promises';
|
|
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
|
-
/**
|
|
33
|
-
* Gets an unsigned 8-bit integer at the specified byte offset from the start of the file.
|
|
34
|
-
* @param offset The offset, in bytes, from the start of the file where to read the data.
|
|
35
|
-
*/
|
|
36
|
-
async getUint8(offset: bigint): Promise<number> {
|
|
37
|
-
const val = new Uint8Array(
|
|
38
|
-
(await this.fileDescriptor.read(Buffer.alloc(1), 0, 1, offset)).buffer.buffer
|
|
39
|
-
).at(0);
|
|
40
|
-
if (val === undefined) {
|
|
41
|
-
throw new Error('something went wrong');
|
|
42
|
-
}
|
|
43
|
-
return val;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Gets an unsigned 16-bit integer at the specified byte offset from the start of the file.
|
|
48
|
-
* @param offset The offset, in bytes, from the start of the file where to read the data.
|
|
49
|
-
*/
|
|
50
|
-
async getUint16(offset: bigint): Promise<number> {
|
|
51
|
-
const val = new Uint16Array(
|
|
52
|
-
(await this.fileDescriptor.read(Buffer.alloc(2), 0, 2, offset)).buffer.buffer
|
|
53
|
-
).at(0);
|
|
54
|
-
if (val === undefined) {
|
|
55
|
-
throw new Error('something went wrong');
|
|
56
|
-
}
|
|
57
|
-
return val;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
|
|
62
|
-
* @param offset The offset, in bytes, from the start of the file where to read the data.
|
|
63
|
-
*/
|
|
64
|
-
async getUint32(offset: bigint): Promise<number> {
|
|
65
|
-
const val = new Uint32Array(
|
|
66
|
-
(await this.fileDescriptor.read(Buffer.alloc(4), 0, 4, offset)).buffer.buffer
|
|
67
|
-
).at(0);
|
|
68
|
-
if (val === undefined) {
|
|
69
|
-
throw new Error('something went wrong');
|
|
70
|
-
}
|
|
71
|
-
return val;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Gets an unsigned 32-bit integer at the specified byte offset from the start of the file.
|
|
76
|
-
* @param offset The offset, in bytes, from the start of the file where to read the data.
|
|
77
|
-
*/
|
|
78
|
-
async getBigUint64(offset: bigint): Promise<bigint> {
|
|
79
|
-
const val = new BigInt64Array(
|
|
80
|
-
(await this.fileDescriptor.read(Buffer.alloc(8), 0, 8, offset)).buffer.buffer
|
|
81
|
-
).at(0);
|
|
82
|
-
if (val === undefined) {
|
|
83
|
-
throw new Error('something went wrong');
|
|
84
|
-
}
|
|
85
|
-
return val;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive.
|
|
90
|
-
* @param startOffsset The offset, in byte, from the start of the file where to start reading the data.
|
|
91
|
-
* @param endOffset The offset, in bytes, from the start of the file where to end reading the data.
|
|
92
|
-
*/
|
|
93
|
-
async slice(startOffsset: bigint, endOffset: bigint): Promise<ArrayBuffer> {
|
|
94
|
-
const bigLength = endOffset - startOffsset;
|
|
95
|
-
if (bigLength > Number.MAX_SAFE_INTEGER) {
|
|
96
|
-
throw new Error('too big slice');
|
|
97
|
-
}
|
|
98
|
-
const length = Number(bigLength);
|
|
99
|
-
return (await this.fileDescriptor.read(Buffer.alloc(length), 0, length, startOffsset)).buffer
|
|
100
|
-
.buffer;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* the length (in bytes) of the data.
|
|
105
|
-
*/
|
|
106
|
-
get length(): bigint {
|
|
107
|
-
return this.size;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import {read, open, 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
|
-
/**
|
|
39
|
-
* Reads data from the file and stores that in the given buffer.
|
|
40
|
-
*
|
|
41
|
-
* If the file is not modified concurrently, the end-of-file is reached when the
|
|
42
|
-
* number of bytes read is zero.
|
|
43
|
-
* @param buffer A buffer that will be filled with the file data read.
|
|
44
|
-
* @param offset The location in the buffer at which to start filling.
|
|
45
|
-
* @param length The number of bytes to read.
|
|
46
|
-
* @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
|
|
47
|
-
* integer, the current file position will remain unchanged.
|
|
48
|
-
* @return Fulfills upon success with a FileReadResult object
|
|
49
|
-
*/
|
|
50
|
-
read = (
|
|
51
|
-
buffer: Buffer,
|
|
52
|
-
offset: number,
|
|
53
|
-
length: number,
|
|
54
|
-
position: number | bigint
|
|
55
|
-
): Promise<FileReadResult> => {
|
|
56
|
-
return new Promise((s) => {
|
|
57
|
-
read(this.fileDescriptor, buffer, offset, length, position, (_err, bytesRead, buffer) =>
|
|
58
|
-
s({bytesRead, buffer})
|
|
59
|
-
);
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
get stat(): BigIntStats {
|
|
64
|
-
return this.stats;
|
|
65
|
-
}
|
|
66
|
-
}
|