@versatiles/container 1.5.0 → 1.5.1

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.
Files changed (2) hide show
  1. package/README.md +61 -2
  2. package/package.json +13 -12
package/README.md CHANGED
@@ -10,9 +10,11 @@ A client library for [VersaTiles containers](https://github.com/versatiles-org/v
10
10
 
11
11
  `npm i @versatiles/container`
12
12
 
13
- # Usage Example
13
+ # Usage Examples
14
14
 
15
- ```js
15
+ ## Basic: read a tile and write to disk
16
+
17
+ ```ts
16
18
  import { Container } from "@versatiles/container";
17
19
  import fs from "fs";
18
20
 
@@ -20,6 +22,63 @@ const container = new Container("https://example.org/planet.versatiles");
20
22
  const header = await container.getHeader();
21
23
  const tile = await container.getTileUncompressed(z, x, y);
22
24
  fs.writeFileSync("tile." + header.tileFormat, tile);
25
+
26
+ // don't forget to close file-backed containers
27
+ await container.close();
28
+ ```
29
+
30
+ ## Inspect tile metadata
31
+
32
+ VersaTiles containers can carry JSON metadata describing vector tile layers:
33
+
34
+ ```ts
35
+ import { Container } from "@versatiles/container";
36
+
37
+ const container = new Container("/path/to/layers.versatiles");
38
+
39
+ const header = await container.getHeader();
40
+ console.log("Format:", header.tileFormat); // e.g. "pbf"
41
+ console.log("Compression:", header.tileCompression);
42
+ console.log("Zoom range:", header.zoomMin, "→", header.zoomMax);
43
+ console.log("Bounding box:", header.bbox);
44
+
45
+ const metadata = await container.getMetadata();
46
+ if (metadata) {
47
+ const parsed = JSON.parse(metadata);
48
+ console.log("Vector layers:", parsed.vector_layers?.length);
49
+ }
50
+
51
+ await container.close();
52
+ ```
53
+
54
+ ## Handle missing tiles
55
+
56
+ Coordinates must lie within the zoom level's grid (`0 <= x, y < 2 ** z`), otherwise `getTile` throws a `RangeError`. For a valid coordinate that simply has no data, the container returns `null`:
57
+
58
+ ```ts
59
+ const tile = await container.getTileUncompressed(12, 100, 4000);
60
+ if (!tile) {
61
+ console.log("Tile does not exist in this container");
62
+ }
63
+ ```
64
+
65
+ ## Custom reader (e.g. S3, in-memory)
66
+
67
+ For custom storage backends, implement the `Reader` interface:
68
+
69
+ ```ts
70
+ import type { Reader } from "@versatiles/container";
71
+ import { Container } from "@versatiles/container";
72
+
73
+ const myReader: Reader = async (offset, length) => {
74
+ // e.g. fetch from an S3 bucket or read from a typed array
75
+ const buffer = Buffer.alloc(length);
76
+ // … fill buffer with data starting at offset …
77
+ return buffer;
78
+ };
79
+
80
+ const container = new Container(myReader);
81
+ const header = await container.getHeader();
23
82
  ```
24
83
 
25
84
  # API
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versatiles/container",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "A client library for reading VersaTiles containers",
5
5
  "scripts": {
6
6
  "build": "rm -rf dist && tsc -p tsconfig.build.json && npm run doc-graph",
@@ -54,20 +54,21 @@
54
54
  ],
55
55
  "devDependencies": {
56
56
  "@eslint/js": "^10.0.1",
57
- "@types/node": "^26.1.1",
58
- "@typescript-eslint/eslint-plugin": "^8.63.0",
59
- "@typescript-eslint/parser": "^8.63.0",
60
- "@versatiles/release-tool": "^2.8.1",
61
- "@vitest/coverage-v8": "^4.1.10",
62
- "eslint": "^10.6.0",
57
+ "@types/node": "^26.2.0",
58
+ "@typescript-eslint/eslint-plugin": "^8.67.0",
59
+ "@typescript-eslint/parser": "^8.67.0",
60
+ "@versatiles/release-tool": "^2.9.0",
61
+ "@vitest/coverage-v8": "^4.1.11",
62
+ "eslint": "^10.8.1",
63
63
  "eslint-config-prettier": "^10.1.8",
64
- "prettier": "^3.9.4",
65
- "tsx": "^4.23.0",
64
+ "prettier": "^3.9.6",
65
+ "tsx": "^4.23.12",
66
66
  "typescript": "^6.0.3",
67
- "typescript-eslint": "^8.63.0",
68
- "vitest": "^4.1.10"
67
+ "typescript-eslint": "^8.67.0",
68
+ "vitest": "^4.1.11"
69
69
  },
70
70
  "allowScripts": {
71
- "esbuild@0.28.1": true
71
+ "esbuild": true,
72
+ "fsevents": true
72
73
  }
73
74
  }