@versatiles/container 1.0.2 → 1.1.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 CHANGED
@@ -22,26 +22,26 @@ fs.writeFileSync('tile.' + header.tile_format, tile);
22
22
 
23
23
  <details>
24
24
 
25
- <summary><h2>Class: <code>VersaTiles</code><a id="class_versatiles"></a></h2></summary>
25
+ <summary><h2>Class: <code>Container</code><a id="class_container"></a></h2></summary>
26
26
 
27
27
  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/8921e07/versatiles-container/src/index.ts#L27">\[src]</a></sup>
28
+ to access tile data, metadata, and other properties within the container. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/index.ts#L38">\[src]</a></sup>
29
29
 
30
30
  <details>
31
31
 
32
- <summary><h3>Constructor: <code>new VersaTiles&#40;source, options&#41;</code></h3></summary>
32
+ <summary><h3>Constructor: <code>new Container&#40;source, options&#41;</code></h3></summary>
33
33
 
34
- Constructs a new instance of the VersaTiles class. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/8921e07/versatiles-container/src/index.ts#L50">\[src]</a></sup>
34
+ Constructs a new instance of the VersaTiles class. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/index.ts#L61">\[src]</a></sup>
35
35
 
36
36
  **Parameters:**
37
37
 
38
38
  * <code>source: string | [Reader](#type_reader)</code>\
39
39
  The data source for the tiles. This can be a URL starting with `http://` or `https://`,
40
40
  a path to a local file, or a custom `Reader` function that reads data chunks based on offset and length.
41
- * <code>options: [Options](#interface_options)</code> (optional)\
41
+ * <code>options: [OpenOptions](#interface_openoptions)</code> (optional)\
42
42
  Optional settings that configure tile handling.
43
43
 
44
- **Returns:** <code>[VersaTiles](#class_versatiles)</code>
44
+ **Returns:** <code>[Container](#class_container)</code>
45
45
 
46
46
  </details>
47
47
 
@@ -49,7 +49,7 @@ Constructs a new instance of the VersaTiles class. <sup><a href="https://github.
49
49
 
50
50
  <summary><h3>Method: <code>getHeader&#40;&#41;</code></h3></summary>
51
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>
52
+ Asynchronously retrieves the header information from the `.versatiles` container. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/index.ts#L85">\[src]</a></sup>
53
53
 
54
54
  **Returns:** <code>Promise<[Header](#interface_header)></code>
55
55
 
@@ -61,9 +61,9 @@ Asynchronously retrieves the header information from the `.versatiles` container
61
61
 
62
62
  Asynchronously retrieves the metadata associated with the `.versatiles` container.\
63
63
  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/8921e07/versatiles-container/src/index.ts#L132">\[src]</a></sup>
64
+ If the container does not include metadata, this method returns `null`. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/index.ts#L132">\[src]</a></sup>
65
65
 
66
- **Returns:** <code>Promise\<null | object></code>
66
+ **Returns:** <code>Promise\<undefined | string></code>
67
67
 
68
68
  </details>
69
69
 
@@ -74,7 +74,7 @@ If the container does not include metadata, this method returns `null`. <sup><a
74
74
  Asynchronously retrieves a specific tile's data as a Buffer. If the tile data is compressed as\
75
75
  defined in the container header, the returned Buffer will contain the compressed data.
76
76
  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/8921e07/versatiles-container/src/index.ts#L158">\[src]</a></sup>
77
+ If the specified tile does not exist, the method returns `null`. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/index.ts#L159">\[src]</a></sup>
78
78
 
79
79
  **Parameters:**
80
80
 
@@ -96,7 +96,7 @@ If the specified tile does not exist, the method returns `null`. <sup><a href="h
96
96
  Asynchronously retrieves a specific tile's uncompressed data as a Buffer. This method first\
97
97
  retrieves the compressed tile data using `getTile` and then decompresses it based on the
98
98
  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/8921e07/versatiles-container/src/index.ts#L206">\[src]</a></sup>
99
+ If the specified tile does not exist, the method returns `null`. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/index.ts#L207">\[src]</a></sup>
100
100
 
101
101
  **Parameters:**
102
102
 
@@ -117,7 +117,7 @@ If the specified tile does not exist, the method returns `null`. <sup><a href="h
117
117
 
118
118
  <summary><h2>Interface: <code>Header</code><a id="interface_header"></a></h2></summary>
119
119
 
120
- Interface for the metadata header of a `*.Versatiles` container. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/8921e07/versatiles-container/src/interfaces.ts#L56">\[src]</a></sup>
120
+ Interface for the metadata header of a `*.Versatiles` container. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/interfaces.ts#L57">\[src]</a></sup>
121
121
 
122
122
  * <code>magic: string</code>\
123
123
  Identifier for the container format, usually "versatiles\_v02".
@@ -125,6 +125,8 @@ Interface for the metadata header of a `*.Versatiles` container. <sup><a href="h
125
125
  Version of the container format, typically "v02".
126
126
  * <code>tileFormat: [Format](#type_format)</code>\
127
127
  The format used for storing tiles.
128
+ * <code>tileMime: string</code>\
129
+ The MIME type of the tiles.
128
130
  * <code>tileCompression: [Compression](#type_compression)</code>\
129
131
  The type of compression applied to tiles.
130
132
  * <code>zoomMin: number</code>\
@@ -146,9 +148,9 @@ Interface for the metadata header of a `*.Versatiles` container. <sup><a href="h
146
148
 
147
149
  <details>
148
150
 
149
- <summary><h2>Interface: <code>Options</code><a id="interface_options"></a></h2></summary>
151
+ <summary><h2>Interface: <code>OpenOptions</code><a id="interface_openoptions"></a></h2></summary>
150
152
 
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>
153
+ Interface for defining the options available for reading a container. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/interfaces.ts#L125">\[src]</a></sup>
152
154
 
153
155
  * <code>tms: boolean</code>\
154
156
  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.
@@ -160,9 +162,9 @@ Interface for defining the options available for reading a container. <sup><a hr
160
162
  <summary><h2>Type: <code>Compression</code><a id="type_compression"></a></h2></summary>
161
163
 
162
164
  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>
165
+ `null` signifies that the data is uncompressed. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/interfaces.ts#L5">\[src]</a></sup>
164
166
 
165
- **Type:** <code>"br" | "gzip" | null</code>
167
+ **Type:** <code>"br" | "gzip" | "raw"</code>
166
168
 
167
169
  </details>
168
170
 
@@ -170,9 +172,9 @@ Supported compression.\
170
172
 
171
173
  <summary><h2>Type: <code>Format</code><a id="type_format"></a></h2></summary>
172
174
 
173
- Supported tile formats. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/8921e07/versatiles-container/src/interfaces.ts#L11">\[src]</a></sup>
175
+ Supported tile formats. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/interfaces.ts#L11">\[src]</a></sup>
174
176
 
175
- **Type:** <code>"avif" | "bin" | "geojson" | "jpeg" | "json" | "pbf" | "png" | "svg" | "topojson" | "webp" | null</code>
177
+ **Type:** <code>"avif" | "bin" | "geojson" | "jpeg" | "json" | "pbf" | "png" | "svg" | "topojson" | "webp"</code>
176
178
 
177
179
  </details>
178
180
 
@@ -182,7 +184,7 @@ Supported tile formats. <sup><a href="https://github.com/versatiles-org/node-ver
182
184
 
183
185
  Type definition for reading content from a VersaTiles container.
184
186
 
185
- This is useful for implementing new container readers, e.g. reading over other network protocols. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/8921e07/versatiles-container/src/interfaces.ts#L37">\[src]</a></sup>
187
+ This is useful for implementing new container readers, e.g. reading over other network protocols. <sup><a href="https://github.com/versatiles-org/node-versatiles/blob/99b1c91/versatiles-container/src/interfaces.ts#L37">\[src]</a></sup>
186
188
 
187
189
  **Type:** <code>(position: number, length: number) => Promise<Buffer></code>
188
190
 
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export type { Compression, Format, Header, OpenOptions, Reader } from './interfa
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 VersaTiles {
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<unknown>;
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
@@ -10,12 +10,24 @@ const FORMATS = {
10
10
  'pbf', 'geojson', 'topojson', 'json',
11
11
  ],
12
12
  };
13
- const COMPRESSIONS = [null, 'gzip', 'br'];
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
+ 'jpeg': '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 VersaTiles {
30
+ export class Container {
19
31
  #options = {
20
32
  tms: false,
21
33
  };
@@ -66,41 +78,29 @@ export class VersaTiles {
66
78
  if (!/^versatiles_v0[12]$/.test(data.toString('utf8', 0, 14))) {
67
79
  throw new Error('Invalid Container');
68
80
  }
81
+ const magic = data.toString('utf8', 0, 14);
69
82
  const version = data.toString('utf8', 11, 14);
83
+ const tileFormat = FORMATS[version][data.readUInt8(14)] ?? 'bin';
84
+ const tileMime = MIMETYPES[tileFormat];
85
+ const tileCompression = COMPRESSIONS[data.readUInt8(15)] ?? 'raw';
86
+ const zoomMin = data.readUInt8(16);
87
+ const zoomMax = data.readUInt8(17);
88
+ let bbox;
89
+ const metaOffset = Number(data.readBigUInt64BE(34));
90
+ const metaLength = Number(data.readBigUInt64BE(42));
91
+ const blockIndexOffset = Number(data.readBigUInt64BE(50));
92
+ const blockIndexLength = Number(data.readBigUInt64BE(58));
70
93
  switch (version) {
71
94
  case 'v01':
72
- this.#header = {
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
- };
95
+ bbox = [data.readFloatBE(18), data.readFloatBE(22), data.readFloatBE(26), data.readFloatBE(30)];
85
96
  break;
86
97
  case 'v02':
87
- this.#header = {
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
- };
98
+ bbox = [data.readInt32BE(18) / 1e7, data.readInt32BE(22) / 1e7, data.readInt32BE(26) / 1e7, data.readInt32BE(30) / 1e7];
100
99
  break;
101
100
  default:
102
101
  throw new Error('Invalid Container');
103
102
  }
103
+ this.#header = { magic, version, tileFormat, tileMime, tileCompression, zoomMin, zoomMax, bbox, metaOffset, metaLength, blockIndexOffset, blockIndexLength };
104
104
  return this.#header;
105
105
  }
106
106
  /**
@@ -115,12 +115,12 @@ export class VersaTiles {
115
115
  return this.#metadata;
116
116
  const header = await this.getHeader();
117
117
  if (header.metaLength === 0) {
118
- this.#metadata = null;
118
+ this.#metadata = undefined;
119
119
  }
120
120
  else {
121
121
  let buffer = await this.read(header.metaOffset, header.metaLength);
122
122
  buffer = await this.#decompress(buffer, header.tileCompression);
123
- this.#metadata = JSON.parse(buffer.toString());
123
+ this.#metadata = buffer.toString();
124
124
  }
125
125
  return this.#metadata;
126
126
  }
@@ -3,11 +3,11 @@
3
3
  * Supported compression.
4
4
  * `null` signifies that the data is uncompressed.
5
5
  */
6
- export type Compression = 'br' | 'gzip' | null;
6
+ export type Compression = 'br' | 'gzip' | 'raw';
7
7
  /**
8
8
  * Supported tile formats.
9
9
  */
10
- export type Format = 'avif' | 'bin' | 'geojson' | 'jpeg' | 'json' | 'pbf' | 'png' | 'svg' | 'topojson' | 'webp' | null;
10
+ export type Format = 'avif' | 'bin' | 'geojson' | 'jpeg' | '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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versatiles/container",
3
- "version": "1.0.2",
3
+ "version": "1.1.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",
@@ -18,7 +18,7 @@
18
18
  "type": "git",
19
19
  "url": "git+https://github.com/versatiles-org/node-versatiles.git"
20
20
  },
21
- "homepage": "https://github.com/versatiles-org/node-versatiles/blob/main/container/README.md",
21
+ "homepage": "https://github.com/versatiles-org/node-versatiles/blob/main/versatiles-container/README.md",
22
22
  "main": "dist/index.js",
23
23
  "types": "dist/index.d.ts",
24
24
  "type": "module",
@@ -46,8 +46,8 @@
46
46
  "versatiles"
47
47
  ],
48
48
  "devDependencies": {
49
- "@types/node": "^20.9.0",
50
- "tsx": "^4.1.0",
49
+ "@types/node": "^20.9.1",
50
+ "tsx": "^4.1.3",
51
51
  "typescript": "^5.2.2",
52
52
  "@versatiles/release-tool": "^1.0.0"
53
53
  }