@versatiles/container 1.0.2 → 1.2.0
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/README.md +53 -106
- package/dist/index.d.ts +5 -5
- package/dist/index.js +40 -42
- package/dist/{decompress.d.ts → lib/decompress.d.ts} +2 -2
- package/dist/{interfaces.d.ts → lib/interfaces.d.ts} +5 -3
- package/dist/{reader_file.d.ts → lib/reader_file.d.ts} +1 -1
- package/dist/{reader_http.d.ts → lib/reader_http.d.ts} +1 -1
- package/package.json +21 -10
- /package/dist/{decompress.js → lib/decompress.js} +0 -0
- /package/dist/{interfaces.js → lib/interfaces.js} +0 -0
- /package/dist/{reader_file.js → lib/reader_file.js} +0 -0
- /package/dist/{reader_http.js → lib/reader_http.js} +0 -0
package/README.md
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
[](https://codecov.io/gh/versatiles-org/node-versatiles)
|
|
2
|
+
[](https://github.com/versatiles-org/node-versatiles-container/actions/workflows/ci.yml)
|
|
3
|
+
|
|
1
4
|
A client library for [VersaTiles containers](https://github.com/versatiles-org/versatiles-spec).
|
|
2
5
|
|
|
3
6
|
# Install
|
|
4
7
|
|
|
5
|
-
`npm i versatiles`
|
|
8
|
+
`npm i @versatiles/container"`
|
|
6
9
|
|
|
7
10
|
# Usage Example
|
|
8
11
|
|
|
9
12
|
```js
|
|
10
|
-
import VersaTiles from 'versatiles';
|
|
13
|
+
import VersaTiles from '@versatiles/container"';
|
|
11
14
|
import fs from 'fs';
|
|
12
15
|
|
|
13
16
|
const container = new VersaTiles('https://example.org/planet.versatiles');
|
|
@@ -20,61 +23,45 @@ fs.writeFileSync('tile.' + header.tile_format, tile);
|
|
|
20
23
|
|
|
21
24
|
<!--- This chapter is generated automatically --->
|
|
22
25
|
|
|
23
|
-
|
|
26
|
+
## Classes
|
|
24
27
|
|
|
25
|
-
|
|
28
|
+
### Class: `Container`<a id="class_container"></a>
|
|
26
29
|
|
|
27
30
|
The `VersaTiles` class is a wrapper around a `.versatiles` container file. It provides methods\
|
|
28
|
-
to access tile data, metadata, and other properties within the container. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/
|
|
29
|
-
|
|
30
|
-
<details>
|
|
31
|
+
to access tile data, metadata, and other properties within the container. <sup><a href="https://github.com/versatiles-org/node-versatiles-container/blob/67a9864/src/index.ts#L38">\[src]</a></sup>
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
#### Constructor: `new Container(source, options)`
|
|
33
34
|
|
|
34
|
-
Constructs a new instance of the VersaTiles class. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/
|
|
35
|
+
Constructs a new instance of the VersaTiles class. <sup><a href="https://github.com/versatiles-org/node-versatiles-container/blob/67a9864/src/index.ts#L59">\[src]</a></sup>
|
|
35
36
|
|
|
36
37
|
**Parameters:**
|
|
37
38
|
|
|
38
39
|
* <code>source: string | [Reader](#type_reader)</code>\
|
|
39
40
|
The data source for the tiles. This can be a URL starting with `http://` or `https://`,
|
|
40
41
|
a path to a local file, or a custom `Reader` function that reads data chunks based on offset and length.
|
|
41
|
-
* <code>options: [
|
|
42
|
+
* <code>options: [OpenOptions](#interface_openoptions)</code> (optional)\
|
|
42
43
|
Optional settings that configure tile handling.
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
</details>
|
|
47
|
-
|
|
48
|
-
<details>
|
|
45
|
+
#### Method: `getHeader()`
|
|
49
46
|
|
|
50
|
-
<
|
|
51
|
-
|
|
52
|
-
Asynchronously retrieves the header information from the `.versatiles` container. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/8921e07/versatiles-container/src/index.ts#L74">\[src]</a></sup>
|
|
47
|
+
Asynchronously retrieves the header information from the `.versatiles` container. <sup><a href="https://github.com/versatiles-org/node-versatiles-container/blob/67a9864/src/index.ts#L81">\[src]</a></sup>
|
|
53
48
|
|
|
54
49
|
**Returns:** <code>Promise<[Header](#interface_header)></code>
|
|
55
50
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
<details>
|
|
59
|
-
|
|
60
|
-
<summary><h3>Method: <code>getMetadata()</code></h3></summary>
|
|
51
|
+
#### Method: `getMetadata()`
|
|
61
52
|
|
|
62
53
|
Asynchronously retrieves the metadata associated with the `.versatiles` container.\
|
|
63
54
|
Metadata typically includes information about `vector_layers` for vector tiles.
|
|
64
|
-
If the container does not include metadata, this method returns `null`. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/
|
|
65
|
-
|
|
66
|
-
**Returns:** <code>Promise\<null | object></code>
|
|
55
|
+
If the container does not include metadata, this method returns `null`. <sup><a href="https://github.com/versatiles-org/node-versatiles-container/blob/67a9864/src/index.ts#L128">\[src]</a></sup>
|
|
67
56
|
|
|
68
|
-
|
|
57
|
+
**Returns:** <code>Promise\<undefined | string></code>
|
|
69
58
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
<summary><h3>Method: <code>getTile(z, x, y)</code></h3></summary>
|
|
59
|
+
#### Method: `getTile(z, x, y)`
|
|
73
60
|
|
|
74
61
|
Asynchronously retrieves a specific tile's data as a Buffer. If the tile data is compressed as\
|
|
75
62
|
defined in the container header, the returned Buffer will contain the compressed data.
|
|
76
63
|
To obtain uncompressed data, use the `getTileUncompressed` method.
|
|
77
|
-
If the specified tile does not exist, the method returns `null`. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/
|
|
64
|
+
If the specified tile does not exist, the method returns `null`. <sup><a href="https://github.com/versatiles-org/node-versatiles-container/blob/67a9864/src/index.ts#L155">\[src]</a></sup>
|
|
78
65
|
|
|
79
66
|
**Parameters:**
|
|
80
67
|
|
|
@@ -87,16 +74,12 @@ If the specified tile does not exist, the method returns `null`. <sup><a href="h
|
|
|
87
74
|
|
|
88
75
|
**Returns:** <code>Promise\<null | Buffer></code>
|
|
89
76
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
<details>
|
|
93
|
-
|
|
94
|
-
<summary><h3>Method: <code>getTileUncompressed(z, x, y)</code></h3></summary>
|
|
77
|
+
#### Method: `getTileUncompressed(z, x, y)`
|
|
95
78
|
|
|
96
79
|
Asynchronously retrieves a specific tile's uncompressed data as a Buffer. This method first\
|
|
97
80
|
retrieves the compressed tile data using `getTile` and then decompresses it based on the
|
|
98
81
|
compression setting in the container header.
|
|
99
|
-
If the specified tile does not exist, the method returns `null`. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/
|
|
82
|
+
If the specified tile does not exist, the method returns `null`. <sup><a href="https://github.com/versatiles-org/node-versatiles-container/blob/67a9864/src/index.ts#L203">\[src]</a></sup>
|
|
100
83
|
|
|
101
84
|
**Parameters:**
|
|
102
85
|
|
|
@@ -109,84 +92,48 @@ If the specified tile does not exist, the method returns `null`. <sup><a href="h
|
|
|
109
92
|
|
|
110
93
|
**Returns:** <code>Promise\<null | Buffer></code>
|
|
111
94
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
* <code>zoomMax: number</code>\
|
|
133
|
-
The maximum zoom level.
|
|
134
|
-
* <code>bbox: \[number, number, number, number]</code>\
|
|
135
|
-
Bounding box coordinates as \[lon\_min, lat\_min, lon\_max, lat\_max].
|
|
136
|
-
* <code>metaOffset: number</code>\
|
|
137
|
-
The byte offset for metadata within the container.
|
|
138
|
-
* <code>metaLength: number</code>\
|
|
139
|
-
The byte size of the metadata. A value of 0 means no metadata.
|
|
140
|
-
* <code>blockIndexOffset: number</code>\
|
|
141
|
-
The byte offset for the block index within the container.
|
|
142
|
-
* <code>blockIndexLength: number</code>\
|
|
143
|
-
The byte size of the block index. A value of 0 indicates no tiles in the container.
|
|
144
|
-
|
|
145
|
-
</details>
|
|
146
|
-
|
|
147
|
-
<details>
|
|
148
|
-
|
|
149
|
-
<summary><h2>Interface: <code>Options</code><a id="interface_options"></a></h2></summary>
|
|
150
|
-
|
|
151
|
-
Interface for defining the options available for reading a container. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/8921e07/versatiles-container/src/interfaces.ts#L123">\[src]</a></sup>
|
|
152
|
-
|
|
153
|
-
* <code>tms: boolean</code>\
|
|
154
|
-
If set to true, uses the [TMS (Tile Map Service) tile ordering](https://wiki.openstreetmap.org/wiki/TMS) where y=0 is the southernmost point.
|
|
155
|
-
|
|
156
|
-
</details>
|
|
157
|
-
|
|
158
|
-
<details>
|
|
159
|
-
|
|
160
|
-
<summary><h2>Type: <code>Compression</code><a id="type_compression"></a></h2></summary>
|
|
161
|
-
|
|
162
|
-
Supported compression.\
|
|
163
|
-
`null` signifies that the data is uncompressed. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/8921e07/versatiles-container/src/interfaces.ts#L5">\[src]</a></sup>
|
|
164
|
-
|
|
165
|
-
**Type:** <code>"br" | "gzip" | null</code>
|
|
166
|
-
|
|
167
|
-
</details>
|
|
168
|
-
|
|
169
|
-
<details>
|
|
170
|
-
|
|
171
|
-
<summary><h2>Type: <code>Format</code><a id="type_format"></a></h2></summary>
|
|
95
|
+
## Interfaces
|
|
96
|
+
|
|
97
|
+
### Interface: `Header`<a id="interface_header"></a>
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
interface {
|
|
101
|
+
bbox: [number, number, number, number];
|
|
102
|
+
blockIndexLength: number;
|
|
103
|
+
blockIndexOffset: number;
|
|
104
|
+
magic: string;
|
|
105
|
+
metaLength: number;
|
|
106
|
+
metaOffset: number;
|
|
107
|
+
tileCompression: [Compression](#type_compression);
|
|
108
|
+
tileFormat: [Format](#type_format);
|
|
109
|
+
tileMime: string;
|
|
110
|
+
version: string;
|
|
111
|
+
zoomMax: number;
|
|
112
|
+
zoomMin: number;
|
|
113
|
+
}
|
|
114
|
+
```
|
|
172
115
|
|
|
173
|
-
|
|
116
|
+
### Interface: `OpenOptions`<a id="interface_openoptions"></a>
|
|
174
117
|
|
|
175
|
-
|
|
118
|
+
```typescript
|
|
119
|
+
interface {
|
|
120
|
+
tms: boolean;
|
|
121
|
+
}
|
|
122
|
+
```
|
|
176
123
|
|
|
177
|
-
|
|
124
|
+
## Type Aliases
|
|
178
125
|
|
|
179
|
-
|
|
126
|
+
### Type: `Compression`<a id="type_compression"></a>
|
|
180
127
|
|
|
181
|
-
|
|
128
|
+
**Type:** <code>"br" | "gzip" | "raw"</code>
|
|
182
129
|
|
|
183
|
-
Type
|
|
130
|
+
### Type: `Format`<a id="type_format"></a>
|
|
184
131
|
|
|
185
|
-
|
|
132
|
+
**Type:** <code>"avif" | "bin" | "geojson" | "jpg" | "json" | "pbf" | "png" | "svg" | "topojson" | "webp"</code>
|
|
186
133
|
|
|
187
|
-
|
|
134
|
+
### Type: `Reader`<a id="type_reader"></a>
|
|
188
135
|
|
|
189
|
-
|
|
136
|
+
**Type:** <code>(position: number, length: number) => Promise\<Buffer></code>
|
|
190
137
|
|
|
191
138
|
# License
|
|
192
139
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/// <reference types="node"
|
|
2
|
-
import type { Block, Header, OpenOptions, Reader, TileIndex } from './interfaces
|
|
3
|
-
export type { Compression, Format, Header, OpenOptions, Reader } from './interfaces
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Block, Header, OpenOptions, Reader, TileIndex } from './lib/interfaces';
|
|
3
|
+
export type { Compression, Format, Header, OpenOptions, Reader } from './lib/interfaces';
|
|
4
4
|
/**
|
|
5
5
|
* The `VersaTiles` class is a wrapper around a `.versatiles` container file. It provides methods
|
|
6
6
|
* to access tile data, metadata, and other properties within the container.
|
|
7
7
|
*/
|
|
8
|
-
export declare class
|
|
8
|
+
export declare class Container {
|
|
9
9
|
#private;
|
|
10
10
|
/**
|
|
11
11
|
* Constructs a new instance of the VersaTiles class.
|
|
@@ -30,7 +30,7 @@ export declare class VersaTiles {
|
|
|
30
30
|
*
|
|
31
31
|
* @returns A promise that resolves with an object representing the metadata.
|
|
32
32
|
*/
|
|
33
|
-
getMetadata(): Promise<
|
|
33
|
+
getMetadata(): Promise<string | undefined>;
|
|
34
34
|
/**
|
|
35
35
|
* Asynchronously retrieves a specific tile's data as a Buffer. If the tile data is compressed as
|
|
36
36
|
* defined in the container header, the returned Buffer will contain the compressed data.
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
1
|
-
import HttpReader from './reader_http
|
|
2
|
-
import FileReader from './reader_file
|
|
3
|
-
import { decompress } from './decompress
|
|
1
|
+
import HttpReader from './lib/reader_http';
|
|
2
|
+
import FileReader from './lib/reader_file';
|
|
3
|
+
import { decompress } from './lib/decompress';
|
|
4
4
|
const FORMATS = {
|
|
5
|
-
'c01': ['png', '
|
|
6
|
-
'v01': ['png', '
|
|
5
|
+
'c01': ['png', 'jpg', 'webp', null, null, null, null, null, null, null, null, null, null, null, null, null, 'pbf'],
|
|
6
|
+
'v01': ['png', 'jpg', 'webp', 'pbf'],
|
|
7
7
|
'v02': [
|
|
8
8
|
'bin', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
|
|
9
|
-
'png', '
|
|
9
|
+
'png', 'jpg', 'webp', 'avif', 'svg', null, null, null, null, null, null, null, null, null, null, null,
|
|
10
10
|
'pbf', 'geojson', 'topojson', 'json',
|
|
11
11
|
],
|
|
12
12
|
};
|
|
13
|
-
const COMPRESSIONS = [
|
|
13
|
+
const COMPRESSIONS = ['raw', 'gzip', 'br'];
|
|
14
|
+
const MIMETYPES = {
|
|
15
|
+
'avif': 'image/avif',
|
|
16
|
+
'bin': 'application/octet-stream',
|
|
17
|
+
'geojson': 'application/geo+json; charset=utf-8',
|
|
18
|
+
'jpg': 'image/jpeg',
|
|
19
|
+
'json': 'application/json; charset=utf-8',
|
|
20
|
+
'pbf': 'application/x-protobuf',
|
|
21
|
+
'png': 'image/png',
|
|
22
|
+
'svg': 'image/svg+xml; charset=utf-8',
|
|
23
|
+
'topojson': 'application/topo+json; charset=utf-8',
|
|
24
|
+
'webp': 'image/webp',
|
|
25
|
+
};
|
|
14
26
|
/**
|
|
15
27
|
* The `VersaTiles` class is a wrapper around a `.versatiles` container file. It provides methods
|
|
16
28
|
* to access tile data, metadata, and other properties within the container.
|
|
17
29
|
*/
|
|
18
|
-
export class
|
|
30
|
+
export class Container {
|
|
19
31
|
#options = {
|
|
20
32
|
tms: false,
|
|
21
33
|
};
|
|
22
34
|
#reader;
|
|
23
|
-
#decompress;
|
|
24
35
|
#header;
|
|
25
36
|
#metadata;
|
|
26
37
|
#blockIndex;
|
|
@@ -49,7 +60,6 @@ export class VersaTiles {
|
|
|
49
60
|
else {
|
|
50
61
|
throw new Error('source must be a string or a Reader');
|
|
51
62
|
}
|
|
52
|
-
this.#decompress = decompress;
|
|
53
63
|
}
|
|
54
64
|
/**
|
|
55
65
|
* Asynchronously retrieves the header information from the `.versatiles` container.
|
|
@@ -66,41 +76,29 @@ export class VersaTiles {
|
|
|
66
76
|
if (!/^versatiles_v0[12]$/.test(data.toString('utf8', 0, 14))) {
|
|
67
77
|
throw new Error('Invalid Container');
|
|
68
78
|
}
|
|
79
|
+
const magic = data.toString('utf8', 0, 14);
|
|
69
80
|
const version = data.toString('utf8', 11, 14);
|
|
81
|
+
const tileFormat = FORMATS[version][data.readUInt8(14)] ?? 'bin';
|
|
82
|
+
const tileMime = MIMETYPES[tileFormat];
|
|
83
|
+
const tileCompression = COMPRESSIONS[data.readUInt8(15)] ?? 'raw';
|
|
84
|
+
const zoomMin = data.readUInt8(16);
|
|
85
|
+
const zoomMax = data.readUInt8(17);
|
|
86
|
+
let bbox;
|
|
87
|
+
const metaOffset = Number(data.readBigUInt64BE(34));
|
|
88
|
+
const metaLength = Number(data.readBigUInt64BE(42));
|
|
89
|
+
const blockIndexOffset = Number(data.readBigUInt64BE(50));
|
|
90
|
+
const blockIndexLength = Number(data.readBigUInt64BE(58));
|
|
70
91
|
switch (version) {
|
|
71
92
|
case 'v01':
|
|
72
|
-
|
|
73
|
-
magic: data.toString('utf8', 0, 14),
|
|
74
|
-
version: version,
|
|
75
|
-
tileFormat: FORMATS[version][data.readUInt8(14)] ?? 'bin',
|
|
76
|
-
tileCompression: COMPRESSIONS[data.readUInt8(15)] ?? null,
|
|
77
|
-
zoomMin: data.readUInt8(16),
|
|
78
|
-
zoomMax: data.readUInt8(17),
|
|
79
|
-
bbox: [data.readFloatBE(18), data.readFloatBE(22), data.readFloatBE(26), data.readFloatBE(30)],
|
|
80
|
-
metaOffset: Number(data.readBigUInt64BE(34)),
|
|
81
|
-
metaLength: Number(data.readBigUInt64BE(42)),
|
|
82
|
-
blockIndexOffset: Number(data.readBigUInt64BE(50)),
|
|
83
|
-
blockIndexLength: Number(data.readBigUInt64BE(58)),
|
|
84
|
-
};
|
|
93
|
+
bbox = [data.readFloatBE(18), data.readFloatBE(22), data.readFloatBE(26), data.readFloatBE(30)];
|
|
85
94
|
break;
|
|
86
95
|
case 'v02':
|
|
87
|
-
|
|
88
|
-
magic: data.toString('utf8', 0, 14),
|
|
89
|
-
version: version,
|
|
90
|
-
tileFormat: FORMATS[version][data.readUInt8(14)] ?? 'bin',
|
|
91
|
-
tileCompression: COMPRESSIONS[data.readUInt8(15)] ?? null,
|
|
92
|
-
zoomMin: data.readUInt8(16),
|
|
93
|
-
zoomMax: data.readUInt8(17),
|
|
94
|
-
bbox: [data.readInt32BE(18) / 1e7, data.readInt32BE(22) / 1e7, data.readInt32BE(26) / 1e7, data.readInt32BE(30) / 1e7],
|
|
95
|
-
metaOffset: Number(data.readBigUInt64BE(34)),
|
|
96
|
-
metaLength: Number(data.readBigUInt64BE(42)),
|
|
97
|
-
blockIndexOffset: Number(data.readBigUInt64BE(50)),
|
|
98
|
-
blockIndexLength: Number(data.readBigUInt64BE(58)),
|
|
99
|
-
};
|
|
96
|
+
bbox = [data.readInt32BE(18) / 1e7, data.readInt32BE(22) / 1e7, data.readInt32BE(26) / 1e7, data.readInt32BE(30) / 1e7];
|
|
100
97
|
break;
|
|
101
98
|
default:
|
|
102
99
|
throw new Error('Invalid Container');
|
|
103
100
|
}
|
|
101
|
+
this.#header = { magic, version, tileFormat, tileMime, tileCompression, zoomMin, zoomMax, bbox, metaOffset, metaLength, blockIndexOffset, blockIndexLength };
|
|
104
102
|
return this.#header;
|
|
105
103
|
}
|
|
106
104
|
/**
|
|
@@ -115,12 +113,12 @@ export class VersaTiles {
|
|
|
115
113
|
return this.#metadata;
|
|
116
114
|
const header = await this.getHeader();
|
|
117
115
|
if (header.metaLength === 0) {
|
|
118
|
-
this.#metadata =
|
|
116
|
+
this.#metadata = undefined;
|
|
119
117
|
}
|
|
120
118
|
else {
|
|
121
119
|
let buffer = await this.read(header.metaOffset, header.metaLength);
|
|
122
|
-
buffer = await
|
|
123
|
-
this.#metadata =
|
|
120
|
+
buffer = await decompress(buffer, header.tileCompression);
|
|
121
|
+
this.#metadata = buffer.toString();
|
|
124
122
|
}
|
|
125
123
|
return this.#metadata;
|
|
126
124
|
}
|
|
@@ -183,7 +181,7 @@ export class VersaTiles {
|
|
|
183
181
|
if (!tile)
|
|
184
182
|
return null;
|
|
185
183
|
const header = await this.getHeader();
|
|
186
|
-
return
|
|
184
|
+
return decompress(tile, header.tileCompression);
|
|
187
185
|
}
|
|
188
186
|
/**
|
|
189
187
|
* Asynchronously retrieves a mapping of tile block indices. The map's keys are formatted as "{z},{x},{y}".
|
|
@@ -198,7 +196,7 @@ export class VersaTiles {
|
|
|
198
196
|
const header = await this.getHeader();
|
|
199
197
|
// read block_index buffer
|
|
200
198
|
let data = await this.read(header.blockIndexOffset, header.blockIndexLength);
|
|
201
|
-
data = await
|
|
199
|
+
data = await decompress(data, 'br');
|
|
202
200
|
// read index from buffer
|
|
203
201
|
const blocks = [];
|
|
204
202
|
switch (header.version) {
|
|
@@ -257,7 +255,7 @@ export class VersaTiles {
|
|
|
257
255
|
if (block.tileIndex)
|
|
258
256
|
return block.tileIndex;
|
|
259
257
|
let buffer = await this.read(block.tileIndexOffset, block.tileIndexLength);
|
|
260
|
-
buffer = await
|
|
258
|
+
buffer = await decompress(buffer, 'br');
|
|
261
259
|
const offsets = new Float64Array(block.tileCount);
|
|
262
260
|
const lengths = new Float64Array(block.tileCount);
|
|
263
261
|
for (let i = 0; i < block.tileCount; i++) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/// <reference types="node"
|
|
2
|
-
import type { Compression } from './interfaces
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Compression } from './interfaces';
|
|
3
3
|
/**
|
|
4
4
|
* Decompresses a buffer using the specified compression algorithm. Currently supports 'br' for Brotli and 'gzip' for GZIP.
|
|
5
5
|
* If the specified algorithm is not supported, the function resolves the promise with the original buffer.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/// <reference types="node"
|
|
1
|
+
/// <reference types="node" />
|
|
2
2
|
/**
|
|
3
3
|
* Supported compression.
|
|
4
4
|
* `null` signifies that the data is uncompressed.
|
|
5
5
|
*/
|
|
6
|
-
export type Compression = 'br' | 'gzip' |
|
|
6
|
+
export type Compression = 'br' | 'gzip' | 'raw';
|
|
7
7
|
/**
|
|
8
8
|
* Supported tile formats.
|
|
9
9
|
*/
|
|
10
|
-
export type Format = 'avif' | 'bin' | 'geojson' | '
|
|
10
|
+
export type Format = 'avif' | 'bin' | 'geojson' | 'jpg' | 'json' | 'pbf' | 'png' | 'svg' | 'topojson' | 'webp';
|
|
11
11
|
/**
|
|
12
12
|
* Type definition for a function that decompresses data.
|
|
13
13
|
*
|
|
@@ -35,6 +35,7 @@ export type Reader = (position: number, length: number) => Promise<Buffer>;
|
|
|
35
35
|
* @property {string} magic - Identifier for the container format, usually "versatiles_v02".
|
|
36
36
|
* @property {string} version - Version of the container format, typically "v02".
|
|
37
37
|
* @property {Format} tileFormat - The format used for storing tiles.
|
|
38
|
+
* @property {string} tileMime - The MIME type of the tiles.
|
|
38
39
|
* @property {Compression} tileCompression - The type of compression applied to tiles.
|
|
39
40
|
* @property {number} zoomMin - The minimum zoom level.
|
|
40
41
|
* @property {number} zoomMax - The maximum zoom level.
|
|
@@ -48,6 +49,7 @@ export interface Header {
|
|
|
48
49
|
magic: string;
|
|
49
50
|
version: string;
|
|
50
51
|
tileFormat: Format;
|
|
52
|
+
tileMime: string;
|
|
51
53
|
tileCompression: Compression;
|
|
52
54
|
zoomMin: number;
|
|
53
55
|
zoomMax: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Reader } from './interfaces
|
|
1
|
+
import type { Reader } from './interfaces';
|
|
2
2
|
/**
|
|
3
3
|
* Creates a file reader function for reading chunks of data from a file. This reader abstracts
|
|
4
4
|
* the file reading process and provides a simple async interface to read data from the specified file.
|
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versatiles/container",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A client library for reading VersaTiles containers",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
7
|
-
"check": "npm run lint && npm run
|
|
7
|
+
"check": "npm run lint && npm run build && npm run test",
|
|
8
8
|
"doc": "npx vrt ts2md src/index.ts tsconfig.build.json | npx vrt insertmd README.md '# API' true",
|
|
9
9
|
"lint": "eslint . --color",
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"prepack": "npm run build && npm run doc",
|
|
11
|
+
"release": "npx vrt release-npm",
|
|
12
|
+
"test-coverage": "NODE_OPTIONS=--experimental-vm-modules jest --coverage",
|
|
13
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
14
|
+
"upgrade": "npm-check-updates -u && rm -f package-lock.json; rm -rf node_modules; npm i && npm update"
|
|
12
15
|
},
|
|
13
16
|
"files": [
|
|
14
17
|
"dist/**/*.js",
|
|
@@ -18,7 +21,7 @@
|
|
|
18
21
|
"type": "git",
|
|
19
22
|
"url": "git+https://github.com/versatiles-org/node-versatiles.git"
|
|
20
23
|
},
|
|
21
|
-
"homepage": "https://github.com/versatiles-org/node-versatiles/blob/main/container/README.md",
|
|
24
|
+
"homepage": "https://github.com/versatiles-org/node-versatiles/blob/main/versatiles-container/README.md",
|
|
22
25
|
"main": "dist/index.js",
|
|
23
26
|
"types": "dist/index.d.ts",
|
|
24
27
|
"type": "module",
|
|
@@ -46,9 +49,17 @@
|
|
|
46
49
|
"versatiles"
|
|
47
50
|
],
|
|
48
51
|
"devDependencies": {
|
|
49
|
-
"@types/
|
|
50
|
-
"
|
|
51
|
-
"typescript": "^
|
|
52
|
-
"@
|
|
52
|
+
"@types/jest": "^29.5.12",
|
|
53
|
+
"@types/node": "^20.11.20",
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^7.0.2",
|
|
55
|
+
"@typescript-eslint/parser": "^7.0.2",
|
|
56
|
+
"@versatiles/release-tool": "^1.2.2",
|
|
57
|
+
"eslint": "^8.57.0",
|
|
58
|
+
"jest": "^29.7.0",
|
|
59
|
+
"npm-check-updates": "^16.14.15",
|
|
60
|
+
"ts-jest": "^29.1.2",
|
|
61
|
+
"ts-node": "^10.9.2",
|
|
62
|
+
"tsx": "^4.7.1",
|
|
63
|
+
"typescript": "^5.3.3"
|
|
53
64
|
}
|
|
54
|
-
}
|
|
65
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|