@osmix/pbf 0.0.1 → 0.0.3
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/CHANGELOG.md +12 -0
- package/README.md +75 -82
- package/dist/src/blobs-to-blocks.d.ts +54 -0
- package/dist/src/blobs-to-blocks.d.ts.map +1 -0
- package/dist/src/blobs-to-blocks.js +75 -0
- package/dist/src/blobs-to-blocks.js.map +1 -0
- package/dist/src/blocks-to-pbf.d.ts +53 -0
- package/dist/src/blocks-to-pbf.d.ts.map +1 -0
- package/dist/{blocks-to-pbf.js → src/blocks-to-pbf.js} +44 -7
- package/dist/src/blocks-to-pbf.js.map +1 -0
- package/dist/src/index.d.ts +37 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +37 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/pbf-to-blobs.d.ts +26 -0
- package/dist/src/pbf-to-blobs.d.ts.map +1 -0
- package/dist/{pbf-to-blobs.js → src/pbf-to-blobs.js} +25 -3
- package/dist/src/pbf-to-blobs.js.map +1 -0
- package/dist/src/pbf-to-blocks.d.ts +63 -0
- package/dist/src/pbf-to-blocks.d.ts.map +1 -0
- package/dist/src/pbf-to-blocks.js +96 -0
- package/dist/src/pbf-to-blocks.js.map +1 -0
- package/dist/{proto → src/proto}/fileformat.d.ts +1 -0
- package/dist/src/proto/fileformat.d.ts.map +1 -0
- package/dist/{proto → src/proto}/fileformat.js +1 -0
- package/dist/src/proto/fileformat.js.map +1 -0
- package/dist/{proto → src/proto}/osmformat.d.ts +1 -0
- package/dist/src/proto/osmformat.d.ts.map +1 -0
- package/dist/{proto → src/proto}/osmformat.js +1 -0
- package/dist/src/proto/osmformat.js.map +1 -0
- package/dist/{spec.d.ts → src/spec.d.ts} +1 -0
- package/dist/src/spec.d.ts.map +1 -0
- package/dist/{spec.js → src/spec.js} +1 -0
- package/dist/src/spec.js.map +1 -0
- package/dist/{utils.d.ts → src/utils.d.ts} +5 -10
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/{utils.js → src/utils.js} +8 -32
- package/dist/src/utils.js.map +1 -0
- package/dist/test/blobs-to-blocks.test.d.ts +2 -0
- package/dist/test/blobs-to-blocks.test.d.ts.map +1 -0
- package/dist/test/blobs-to-blocks.test.js +61 -0
- package/dist/test/blobs-to-blocks.test.js.map +1 -0
- package/dist/test/helpers.d.ts +11 -0
- package/dist/test/helpers.d.ts.map +1 -0
- package/dist/test/helpers.js +58 -0
- package/dist/test/helpers.js.map +1 -0
- package/dist/test/pbf-to-blobs.test.d.ts +2 -0
- package/dist/test/pbf-to-blobs.test.d.ts.map +1 -0
- package/dist/test/pbf-to-blobs.test.js +77 -0
- package/dist/test/pbf-to-blobs.test.js.map +1 -0
- package/dist/test/read.bench.d.ts +2 -0
- package/dist/test/read.bench.d.ts.map +1 -0
- package/dist/test/read.bench.js +31 -0
- package/dist/test/read.bench.js.map +1 -0
- package/dist/test/read.test.d.ts +2 -0
- package/dist/test/read.test.d.ts.map +1 -0
- package/dist/test/read.test.js +34 -0
- package/dist/test/read.test.js.map +1 -0
- package/dist/test/streams.test.d.ts +2 -0
- package/dist/test/streams.test.d.ts.map +1 -0
- package/dist/test/streams.test.js +78 -0
- package/dist/test/streams.test.js.map +1 -0
- package/dist/test/utils.d.ts +25 -0
- package/dist/test/utils.d.ts.map +1 -0
- package/dist/test/utils.js +47 -0
- package/dist/test/utils.js.map +1 -0
- package/dist/test/utils.test.d.ts +2 -0
- package/dist/test/utils.test.d.ts.map +1 -0
- package/dist/test/utils.test.js +44 -0
- package/dist/test/utils.test.js.map +1 -0
- package/dist/test/write.test.d.ts +2 -0
- package/dist/test/write.test.d.ts.map +1 -0
- package/dist/test/write.test.js +69 -0
- package/dist/test/write.test.js.map +1 -0
- package/package.json +7 -7
- package/src/blobs-to-blocks.ts +78 -7
- package/src/blocks-to-pbf.ts +42 -5
- package/src/index.ts +29 -0
- package/src/pbf-to-blobs.ts +24 -3
- package/src/pbf-to-blocks.ts +52 -12
- package/src/utils.ts +0 -7
- package/test/blobs-to-blocks.test.ts +25 -19
- package/test/pbf-to-blobs.test.ts +23 -17
- package/test/read.bench.ts +8 -4
- package/test/read.test.ts +5 -5
- package/test/streams.test.ts +22 -13
- package/test/utils.test.ts +8 -8
- package/test/utils.ts +8 -8
- package/test/write.test.ts +14 -9
- package/dist/blobs-to-blocks.d.ts +0 -5
- package/dist/blobs-to-blocks.js +0 -21
- package/dist/blocks-to-pbf.d.ts +0 -16
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -8
- package/dist/pbf-to-blobs.d.ts +0 -6
- package/dist/pbf-to-blocks.d.ts +0 -20
- package/dist/pbf-to-blocks.js +0 -53
- package/test/utils.bun.test.ts +0 -327
- package/test/verify-pbf-reading.bun.test.ts +0 -39
- package/vitest.config.ts +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @osmix/pbf
|
|
2
2
|
|
|
3
|
+
## 0.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d001d9a: Refactor to align around new main external API
|
|
8
|
+
|
|
9
|
+
## 0.0.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 33d9c12: Modify types to take Uint8Array<ArrayBufferLike> for compatiblity
|
|
14
|
+
|
|
3
15
|
## 0.0.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
# @osmix/pbf
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Low-level TypeScript library for reading and writing OpenStreetMap PBF data. Stays close to the official protobuf schema (`osmformat.proto`, `fileformat.proto`), exposes predictable types, and runs in Node.js and modern browsers via Web Streams and native compression primitives.
|
|
4
4
|
|
|
5
5
|
## Highlights
|
|
6
6
|
|
|
7
|
-
- Parse headers and primitive blocks from `ArrayBufferLike`, async iterables, or Web `ReadableStream`s.
|
|
8
|
-
-
|
|
9
|
-
- Serialize header and primitive blocks back to spec-compliant blobs with size guardrails
|
|
10
|
-
-
|
|
11
|
-
-
|
|
7
|
+
- **Parse** headers and primitive blocks from `ArrayBufferLike`, async iterables, or Web `ReadableStream`s.
|
|
8
|
+
- **Stream** with `TransformStream` helpers instead of buffering entire files in memory.
|
|
9
|
+
- **Serialize** header and primitive blocks back to spec-compliant blobs with size guardrails.
|
|
10
|
+
- **Types** generated from protobuf schemas for type-safe access to OSM data structures.
|
|
11
|
+
- **Utilities** for compression, concatenation, and big-endian encoding tuned for the PBF format.
|
|
12
12
|
|
|
13
13
|
## Installation
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
|
-
|
|
16
|
+
bun add @osmix/pbf
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## Usage
|
|
@@ -25,8 +25,7 @@ npm install @osmix/pbf
|
|
|
25
25
|
```ts
|
|
26
26
|
import { readOsmPbf } from "@osmix/pbf"
|
|
27
27
|
|
|
28
|
-
const
|
|
29
|
-
const { header, blocks } = await readOsmPbf(response.body)
|
|
28
|
+
const { header, blocks } = await readOsmPbf(Bun.file('./monaco.pbf').stream())
|
|
30
29
|
|
|
31
30
|
console.log(header.required_features)
|
|
32
31
|
|
|
@@ -37,108 +36,102 @@ for await (const block of blocks) {
|
|
|
37
36
|
}
|
|
38
37
|
```
|
|
39
38
|
|
|
40
|
-
###
|
|
39
|
+
### Streaming with TransformStreams
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
For large files, use `TransformStream` helpers to process data incrementally:
|
|
43
42
|
|
|
44
43
|
```ts
|
|
45
|
-
import {
|
|
44
|
+
import {
|
|
45
|
+
OsmPbfBytesToBlocksTransformStream,
|
|
46
|
+
OsmBlocksToPbfBytesTransformStream,
|
|
47
|
+
} from "@osmix/pbf"
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
await response.body
|
|
49
|
+
// Decode PBF bytes into blocks
|
|
50
|
+
const blocksStream = response.body!
|
|
50
51
|
.pipeThrough(new OsmPbfBytesToBlocksTransformStream())
|
|
51
|
-
.pipeTo(
|
|
52
|
-
new WritableStream({
|
|
53
|
-
write: (block) => {
|
|
54
|
-
if ("primitivegroup" in block) {
|
|
55
|
-
// Handle primitive data blocks.
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
console.log("Header bbox", block.bbox)
|
|
60
|
-
},
|
|
61
|
-
}),
|
|
62
|
-
)
|
|
63
|
-
```
|
|
64
52
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
53
|
+
// Encode blocks back to PBF bytes
|
|
54
|
+
const pbfStream = blocksStream
|
|
55
|
+
.pipeThrough(new OsmBlocksToPbfBytesTransformStream())
|
|
56
|
+
```
|
|
68
57
|
|
|
69
|
-
|
|
58
|
+
### Write a PBF file
|
|
70
59
|
|
|
71
60
|
```ts
|
|
72
|
-
import {
|
|
73
|
-
|
|
74
|
-
const response = await fetch("/fixtures/monaco.pbf")
|
|
75
|
-
const { header, blocks } = await readOsmPbf(response.body)
|
|
76
|
-
|
|
77
|
-
const chunks: Uint8Array[] = [await osmBlockToPbfBlobBytes(header)]
|
|
78
|
-
for await (const block of blocks) chunks.push(await osmBlockToPbfBlobBytes(block))
|
|
61
|
+
import { osmBlockToPbfBlobBytes } from "@osmix/pbf"
|
|
79
62
|
|
|
80
|
-
|
|
63
|
+
// Serialize a header block
|
|
64
|
+
const headerBytes = await osmBlockToPbfBlobBytes({
|
|
65
|
+
required_features: ["OsmSchema-V0.6", "DenseNodes"],
|
|
66
|
+
optional_features: [],
|
|
67
|
+
})
|
|
81
68
|
|
|
69
|
+
// Serialize a primitive block
|
|
70
|
+
const dataBytes = await osmBlockToPbfBlobBytes(primitiveBlock)
|
|
82
71
|
```
|
|
83
72
|
|
|
84
|
-
|
|
73
|
+
## API
|
|
85
74
|
|
|
86
|
-
|
|
75
|
+
### Reading
|
|
87
76
|
|
|
88
|
-
|
|
89
|
-
|
|
77
|
+
| Export | Description |
|
|
78
|
+
|--------|-------------|
|
|
79
|
+
| `readOsmPbf(data)` | Parse PBF from buffer/stream/iterable into header + blocks generator |
|
|
80
|
+
| `OsmPbfBytesToBlocksTransformStream` | TransformStream: raw bytes → header/primitive blocks |
|
|
81
|
+
| `createOsmPbfBlobGenerator()` | Stateful parser that extracts compressed blobs from byte chunks |
|
|
82
|
+
| `osmPbfBlobsToBlocksGenerator(blobs)` | Async generator: compressed blobs → typed blocks |
|
|
83
|
+
| `readOsmHeaderBlock(blob)` | Decompress and parse a header blob |
|
|
84
|
+
| `readOsmPrimitiveBlock(blob)` | Decompress and parse a primitive blob |
|
|
90
85
|
|
|
91
|
-
|
|
92
|
-
const { header, blocks } = await readOsmPbf(response.body)
|
|
86
|
+
### Writing
|
|
93
87
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
controller.close()
|
|
99
|
-
},
|
|
100
|
-
})
|
|
88
|
+
| Export | Description |
|
|
89
|
+
|--------|-------------|
|
|
90
|
+
| `osmBlockToPbfBlobBytes(block)` | Serialize a block to spec-compliant PBF bytes |
|
|
91
|
+
| `OsmBlocksToPbfBytesTransformStream` | TransformStream: header/primitive blocks → PBF bytes |
|
|
101
92
|
|
|
102
|
-
|
|
103
|
-
.pipeThrough(new OsmBlocksToPbfBytesTransformStream())
|
|
104
|
-
.pipeTo(new WritableStream({ write: persistChunk }))
|
|
105
|
-
```
|
|
93
|
+
### Types
|
|
106
94
|
|
|
107
|
-
|
|
95
|
+
| Export | Description |
|
|
96
|
+
|--------|-------------|
|
|
97
|
+
| `OsmPbfHeaderBlock` | Parsed header with required/optional features and bbox |
|
|
98
|
+
| `OsmPbfBlock` | Parsed primitive block with string table and groups |
|
|
99
|
+
| `OsmPbfGroup` | Primitive group containing nodes, ways, or relations |
|
|
100
|
+
| `OsmPbfDenseNodes` | Delta-encoded dense node format |
|
|
101
|
+
| `OsmPbfWay`, `OsmPbfRelation`, `OsmPbfNode` | Raw entity structures |
|
|
108
102
|
|
|
109
|
-
|
|
103
|
+
### Constants
|
|
110
104
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
- `osmBlockToPbfBlobBytes(block)` – Serializes a single header or primitive block, returning the BlobHeader length prefix and blob bytes as one `Uint8Array`.
|
|
117
|
-
- Utility exports: `toAsyncGenerator`, `compress`, `decompress`, `concatUint8`, `uint32BE`, and the size constants from `spec.ts`. Compression helpers detect Bun and fall back to Node's zlib bindings for compatibility.
|
|
118
|
-
- Generated protobuf helpers: `readHeaderBlock`, `writeHeaderBlock`, `readPrimitiveBlock`, `writePrimitiveBlock`, plus the associated TypeScript types (`OsmPbfBlock`, `OsmPbfHeaderBlock`, `OsmPbfBlob`, and friends).
|
|
105
|
+
| Export | Description |
|
|
106
|
+
|--------|-------------|
|
|
107
|
+
| `MAX_BLOB_SIZE_BYTES` | Maximum blob size per spec (32 MiB) |
|
|
108
|
+
| `RECOMMENDED_BLOB_SIZE_BYTES` | Recommended blob size (16 MiB) |
|
|
109
|
+
| `MAX_ENTITIES_PER_BLOCK` | Recommended max entities per block (8,000) |
|
|
119
110
|
|
|
120
|
-
##
|
|
111
|
+
## Related Packages
|
|
121
112
|
|
|
122
|
-
- [`@osmix/json`](../json/README.md) – Converts parsed blocks into ergonomic JSON
|
|
123
|
-
- [`@osmix/core`](../core/README.md) –
|
|
124
|
-
- [`@osmix/change`](../change/README.md) –
|
|
113
|
+
- [`@osmix/json`](../json/README.md) – Converts parsed blocks into ergonomic JSON entities.
|
|
114
|
+
- [`@osmix/core`](../core/README.md) – In-memory storage using these readers/writers.
|
|
115
|
+
- [`@osmix/change`](../change/README.md) – Changeset and merge workflows.
|
|
125
116
|
|
|
126
|
-
## Environment and
|
|
117
|
+
## Environment and Limitations
|
|
127
118
|
|
|
128
|
-
- Requires runtimes with Web Streams + `CompressionStream` / `DecompressionStream`
|
|
129
|
-
- Only `zlib_data` blobs are supported
|
|
130
|
-
- When working with Node `Readable` / `Writable` streams, adapt them to Web Streams (`stream/web`)
|
|
119
|
+
- Requires runtimes with Web Streams + `CompressionStream` / `DecompressionStream` (modern browsers, Node 20+, Bun).
|
|
120
|
+
- Only `zlib_data` blobs are supported; files with `raw` or `lzma` payloads will throw.
|
|
121
|
+
- When working with Node `Readable` / `Writable` streams, adapt them to Web Streams (`stream/web`) first.
|
|
131
122
|
|
|
132
|
-
### Memory
|
|
123
|
+
### Memory Guidance
|
|
133
124
|
|
|
134
|
-
- Prefer streaming transforms (`OsmPbfBytesToBlocksTransformStream` → `OsmBlocksToPbfBytesTransformStream`) for large extracts
|
|
135
|
-
-
|
|
136
|
-
- In browsers,
|
|
125
|
+
- Prefer streaming transforms (`OsmPbfBytesToBlocksTransformStream` → `OsmBlocksToPbfBytesTransformStream`) for large extracts.
|
|
126
|
+
- Materializing full files requires memory proportional to input size plus compression buffers.
|
|
127
|
+
- In browsers, watch heap limits (typically 2–4 GB).
|
|
137
128
|
|
|
138
129
|
## Development
|
|
139
130
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
131
|
+
```sh
|
|
132
|
+
bun run test packages/pbf
|
|
133
|
+
bun run lint packages/pbf
|
|
134
|
+
bun run typecheck packages/pbf
|
|
135
|
+
```
|
|
143
136
|
|
|
144
137
|
Run `bun run check` at the repo root before publishing to ensure formatting, lint, and type coverage.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Blob-to-block conversion utilities.
|
|
3
|
+
*
|
|
4
|
+
* Handles decompression and protobuf decoding of raw OSM PBF blobs into
|
|
5
|
+
* typed header and primitive block structures.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { type OsmPbfBlock, type OsmPbfHeaderBlock } from "./proto/osmformat";
|
|
10
|
+
/**
|
|
11
|
+
* Decompress and decode a stream of raw PBF blobs into typed blocks.
|
|
12
|
+
*
|
|
13
|
+
* This async generator handles the transition from compressed bytes to parsed
|
|
14
|
+
* protobuf structures. The first blob is always decoded as a header block;
|
|
15
|
+
* subsequent blobs are decoded as primitive blocks containing OSM entities.
|
|
16
|
+
*
|
|
17
|
+
* @param blobs - Async or sync generator yielding compressed blob payloads.
|
|
18
|
+
* @param decompress - Optional decompression function (defaults to Web Streams zlib).
|
|
19
|
+
* @yields Header block first, then primitive blocks.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { osmPbfBlobsToBlocksGenerator, createOsmPbfBlobGenerator } from "@osmix/pbf"
|
|
24
|
+
*
|
|
25
|
+
* const generateBlobs = createOsmPbfBlobGenerator()
|
|
26
|
+
* const blobsGen = (async function* () {
|
|
27
|
+
* for await (const chunk of stream) {
|
|
28
|
+
* yield* generateBlobs(chunk)
|
|
29
|
+
* }
|
|
30
|
+
* })()
|
|
31
|
+
*
|
|
32
|
+
* for await (const block of osmPbfBlobsToBlocksGenerator(blobsGen)) {
|
|
33
|
+
* // First iteration yields header, rest yield primitive blocks
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function osmPbfBlobsToBlocksGenerator(blobs: AsyncGenerator<Uint8Array<ArrayBuffer>> | Generator<Uint8Array<ArrayBuffer>>, decompress?: (data: Uint8Array<ArrayBuffer>) => Promise<Uint8Array<ArrayBuffer>>): AsyncGenerator<OsmPbfHeaderBlock | OsmPbfBlock, void, unknown>;
|
|
38
|
+
/**
|
|
39
|
+
* Decompress and parse a header block from a compressed blob.
|
|
40
|
+
*
|
|
41
|
+
* @param compressedBlob - Zlib-compressed protobuf header blob.
|
|
42
|
+
* @param decompress - Optional decompression function.
|
|
43
|
+
* @returns Parsed header block with required/optional features and bbox.
|
|
44
|
+
*/
|
|
45
|
+
export declare function readOsmHeaderBlock(compressedBlob: Uint8Array<ArrayBuffer>, decompress?: (data: Uint8Array<ArrayBuffer>) => Promise<Uint8Array<ArrayBuffer>>): Promise<OsmPbfHeaderBlock>;
|
|
46
|
+
/**
|
|
47
|
+
* Decompress and parse a primitive block from a compressed blob.
|
|
48
|
+
*
|
|
49
|
+
* @param compressedBlob - Zlib-compressed protobuf primitive blob.
|
|
50
|
+
* @param decompress - Optional decompression function.
|
|
51
|
+
* @returns Parsed primitive block with string table and primitive groups.
|
|
52
|
+
*/
|
|
53
|
+
export declare function readOsmPrimitiveBlock(compressedBlob: Uint8Array<ArrayBuffer>, decompress?: (data: Uint8Array<ArrayBuffer>) => Promise<Uint8Array<ArrayBuffer>>): Promise<OsmPbfBlock>;
|
|
54
|
+
//# sourceMappingURL=blobs-to-blocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blobs-to-blocks.d.ts","sourceRoot":"","sources":["../../src/blobs-to-blocks.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACN,KAAK,WAAW,EAChB,KAAK,iBAAiB,EAGtB,MAAM,mBAAmB,CAAA;AAG1B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAuB,4BAA4B,CAClD,KAAK,EACF,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,GACvC,SAAS,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,EACrC,UAAU,GAAE,CACX,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,KACzB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAiB,kEAWrD;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACvC,cAAc,EAAE,UAAU,CAAC,WAAW,CAAC,EACvC,UAAU,GAAE,CACX,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,KACzB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAiB,GACnD,OAAO,CAAC,iBAAiB,CAAC,CAI5B;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CAC1C,cAAc,EAAE,UAAU,CAAC,WAAW,CAAC,EACvC,UAAU,GAAE,CACX,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,KACzB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAiB,GACnD,OAAO,CAAC,WAAW,CAAC,CAItB"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Blob-to-block conversion utilities.
|
|
3
|
+
*
|
|
4
|
+
* Handles decompression and protobuf decoding of raw OSM PBF blobs into
|
|
5
|
+
* typed header and primitive block structures.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import Pbf from "pbf";
|
|
10
|
+
import { readHeaderBlock, readPrimitiveBlock, } from "./proto/osmformat";
|
|
11
|
+
import { webDecompress } from "./utils";
|
|
12
|
+
/**
|
|
13
|
+
* Decompress and decode a stream of raw PBF blobs into typed blocks.
|
|
14
|
+
*
|
|
15
|
+
* This async generator handles the transition from compressed bytes to parsed
|
|
16
|
+
* protobuf structures. The first blob is always decoded as a header block;
|
|
17
|
+
* subsequent blobs are decoded as primitive blocks containing OSM entities.
|
|
18
|
+
*
|
|
19
|
+
* @param blobs - Async or sync generator yielding compressed blob payloads.
|
|
20
|
+
* @param decompress - Optional decompression function (defaults to Web Streams zlib).
|
|
21
|
+
* @yields Header block first, then primitive blocks.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { osmPbfBlobsToBlocksGenerator, createOsmPbfBlobGenerator } from "@osmix/pbf"
|
|
26
|
+
*
|
|
27
|
+
* const generateBlobs = createOsmPbfBlobGenerator()
|
|
28
|
+
* const blobsGen = (async function* () {
|
|
29
|
+
* for await (const chunk of stream) {
|
|
30
|
+
* yield* generateBlobs(chunk)
|
|
31
|
+
* }
|
|
32
|
+
* })()
|
|
33
|
+
*
|
|
34
|
+
* for await (const block of osmPbfBlobsToBlocksGenerator(blobsGen)) {
|
|
35
|
+
* // First iteration yields header, rest yield primitive blocks
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export async function* osmPbfBlobsToBlocksGenerator(blobs, decompress = webDecompress) {
|
|
40
|
+
let headerRead = false;
|
|
41
|
+
for await (const blob of blobs) {
|
|
42
|
+
if (!headerRead) {
|
|
43
|
+
headerRead = true;
|
|
44
|
+
yield readOsmHeaderBlock(blob, decompress);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
yield readOsmPrimitiveBlock(blob, decompress);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Decompress and parse a header block from a compressed blob.
|
|
53
|
+
*
|
|
54
|
+
* @param compressedBlob - Zlib-compressed protobuf header blob.
|
|
55
|
+
* @param decompress - Optional decompression function.
|
|
56
|
+
* @returns Parsed header block with required/optional features and bbox.
|
|
57
|
+
*/
|
|
58
|
+
export async function readOsmHeaderBlock(compressedBlob, decompress = webDecompress) {
|
|
59
|
+
const decompressedBlob = await decompress(compressedBlob);
|
|
60
|
+
const pbf = new Pbf(decompressedBlob);
|
|
61
|
+
return readHeaderBlock(pbf);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Decompress and parse a primitive block from a compressed blob.
|
|
65
|
+
*
|
|
66
|
+
* @param compressedBlob - Zlib-compressed protobuf primitive blob.
|
|
67
|
+
* @param decompress - Optional decompression function.
|
|
68
|
+
* @returns Parsed primitive block with string table and primitive groups.
|
|
69
|
+
*/
|
|
70
|
+
export async function readOsmPrimitiveBlock(compressedBlob, decompress = webDecompress) {
|
|
71
|
+
const decompressedBlob = await decompress(compressedBlob);
|
|
72
|
+
const pbf = new Pbf(decompressedBlob);
|
|
73
|
+
return readPrimitiveBlock(pbf);
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=blobs-to-blocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blobs-to-blocks.js","sourceRoot":"","sources":["../../src/blobs-to-blocks.ts"],"names":[],"mappings":"AAAA;;;;;;;GA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
3
|
+
*
|
|
4
|
+
* Converts parsed OSM header and primitive blocks back into spec-compliant
|
|
5
|
+
* PBF byte sequences with proper framing, compression, and size validation.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { OsmPbfBlock, OsmPbfHeaderBlock } from "./proto/osmformat";
|
|
10
|
+
/**
|
|
11
|
+
* Serialize a header or primitive block into spec-compliant PBF bytes.
|
|
12
|
+
*
|
|
13
|
+
* Handles protobuf encoding, zlib compression, blob wrapping, and length prefixing.
|
|
14
|
+
* Validates output against OSM PBF specification size limits and logs warnings
|
|
15
|
+
* if recommended sizes are exceeded.
|
|
16
|
+
*
|
|
17
|
+
* @param block - Parsed header or primitive block to encode.
|
|
18
|
+
* @param compress - Optional compression function (defaults to Web Streams zlib).
|
|
19
|
+
* @returns Complete blob bytes: 4-byte length prefix + BlobHeader + Blob.
|
|
20
|
+
* @throws If blob exceeds maximum size limits (64 KiB header, 32 MiB data).
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { osmBlockToPbfBlobBytes } from "@osmix/pbf"
|
|
25
|
+
*
|
|
26
|
+
* const headerBytes = await osmBlockToPbfBlobBytes({
|
|
27
|
+
* required_features: ["OsmSchema-V0.6", "DenseNodes"],
|
|
28
|
+
* optional_features: [],
|
|
29
|
+
* })
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function osmBlockToPbfBlobBytes(block: OsmPbfBlock | OsmPbfHeaderBlock, compress?: (data: Uint8Array<ArrayBuffer>) => Promise<Uint8Array<ArrayBuffer>>): Promise<Uint8Array<ArrayBufferLike>>;
|
|
33
|
+
/**
|
|
34
|
+
* Web `TransformStream` that encodes OSM blocks into PBF byte chunks.
|
|
35
|
+
*
|
|
36
|
+
* Accepts a stream of header and primitive blocks and outputs spec-compliant
|
|
37
|
+
* PBF bytes. The header block must be the first item in the stream.
|
|
38
|
+
*
|
|
39
|
+
* @throws If a primitive block is received before the header.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { OsmBlocksToPbfBytesTransformStream } from "@osmix/pbf"
|
|
44
|
+
*
|
|
45
|
+
* const pbfStream = blocksStream.pipeThrough(new OsmBlocksToPbfBytesTransformStream())
|
|
46
|
+
* await pbfStream.pipeTo(writableFile)
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare class OsmBlocksToPbfBytesTransformStream extends TransformStream<OsmPbfHeaderBlock | OsmPbfBlock, Uint8Array> {
|
|
50
|
+
headerEnqueued: boolean;
|
|
51
|
+
constructor();
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=blocks-to-pbf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocks-to-pbf.d.ts","sourceRoot":"","sources":["../../src/blocks-to-pbf.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAUvE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,sBAAsB,CAC3C,KAAK,EAAE,WAAW,GAAG,iBAAiB,EACtC,QAAQ,GAAE,CACT,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,KACzB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAe,wCAqDnD;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,kCAAmC,SAAQ,eAAe,CACtE,iBAAiB,GAAG,WAAW,EAC/B,UAAU,CACV;IACA,cAAc,UAAQ;;CAYtB"}
|
|
@@ -1,15 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Block-to-PBF serialization utilities.
|
|
3
|
+
*
|
|
4
|
+
* Converts parsed OSM header and primitive blocks back into spec-compliant
|
|
5
|
+
* PBF byte sequences with proper framing, compression, and size validation.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
1
9
|
import Pbf from "pbf";
|
|
2
10
|
import { writeBlob, writeBlobHeader } from "./proto/fileformat";
|
|
3
11
|
import { writeHeaderBlock, writePrimitiveBlock } from "./proto/osmformat";
|
|
4
12
|
import { MAX_BLOB_SIZE_BYTES, MAX_HEADER_SIZE_BYTES, RECOMMENDED_BLOB_SIZE_BYTES, RECOMMENDED_HEADER_SIZE_BYTES, } from "./spec";
|
|
5
|
-
import {
|
|
13
|
+
import { concatUint8, uint32BE, webCompress } from "./utils";
|
|
6
14
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
15
|
+
* Serialize a header or primitive block into spec-compliant PBF bytes.
|
|
16
|
+
*
|
|
17
|
+
* Handles protobuf encoding, zlib compression, blob wrapping, and length prefixing.
|
|
18
|
+
* Validates output against OSM PBF specification size limits and logs warnings
|
|
19
|
+
* if recommended sizes are exceeded.
|
|
20
|
+
*
|
|
9
21
|
* @param block - Parsed header or primitive block to encode.
|
|
10
|
-
* @
|
|
22
|
+
* @param compress - Optional compression function (defaults to Web Streams zlib).
|
|
23
|
+
* @returns Complete blob bytes: 4-byte length prefix + BlobHeader + Blob.
|
|
24
|
+
* @throws If blob exceeds maximum size limits (64 KiB header, 32 MiB data).
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { osmBlockToPbfBlobBytes } from "@osmix/pbf"
|
|
29
|
+
*
|
|
30
|
+
* const headerBytes = await osmBlockToPbfBlobBytes({
|
|
31
|
+
* required_features: ["OsmSchema-V0.6", "DenseNodes"],
|
|
32
|
+
* optional_features: [],
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
11
35
|
*/
|
|
12
|
-
export async function osmBlockToPbfBlobBytes(block) {
|
|
36
|
+
export async function osmBlockToPbfBlobBytes(block, compress = webCompress) {
|
|
13
37
|
const contentPbf = new Pbf();
|
|
14
38
|
let type;
|
|
15
39
|
if ("primitivegroup" in block) {
|
|
@@ -54,8 +78,20 @@ export async function osmBlockToPbfBlobBytes(block) {
|
|
|
54
78
|
return concatUint8(blobHeaderSize, blobHeader, blob);
|
|
55
79
|
}
|
|
56
80
|
/**
|
|
57
|
-
* Web `TransformStream` that
|
|
58
|
-
*
|
|
81
|
+
* Web `TransformStream` that encodes OSM blocks into PBF byte chunks.
|
|
82
|
+
*
|
|
83
|
+
* Accepts a stream of header and primitive blocks and outputs spec-compliant
|
|
84
|
+
* PBF bytes. The header block must be the first item in the stream.
|
|
85
|
+
*
|
|
86
|
+
* @throws If a primitive block is received before the header.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* import { OsmBlocksToPbfBytesTransformStream } from "@osmix/pbf"
|
|
91
|
+
*
|
|
92
|
+
* const pbfStream = blocksStream.pipeThrough(new OsmBlocksToPbfBytesTransformStream())
|
|
93
|
+
* await pbfStream.pipeTo(writableFile)
|
|
94
|
+
* ```
|
|
59
95
|
*/
|
|
60
96
|
export class OsmBlocksToPbfBytesTransformStream extends TransformStream {
|
|
61
97
|
headerEnqueued = false;
|
|
@@ -71,3 +107,4 @@ export class OsmBlocksToPbfBytesTransformStream extends TransformStream {
|
|
|
71
107
|
});
|
|
72
108
|
}
|
|
73
109
|
}
|
|
110
|
+
//# sourceMappingURL=blocks-to-pbf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocks-to-pbf.js","sourceRoot":"","sources":["../../src/blocks-to-pbf.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAE/D,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACzE,OAAO,EACN,mBAAmB,EACnB,qBAAqB,EACrB,2BAA2B,EAC3B,6BAA6B,GAC7B,MAAM,QAAQ,CAAA;AACf,OAAO,EAAE,WAAW,EAAE,Q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ix/pbf - Low-level OSM PBF parsing and serialization.
|
|
3
|
+
*
|
|
4
|
+
* Provides streaming primitives for reading and writing OpenStreetMap PBF files
|
|
5
|
+
* using Web Streams and native compression APIs. Stays close to the official
|
|
6
|
+
* protobuf schema (`osmformat.proto`, `fileformat.proto`) while exposing
|
|
7
|
+
* predictable TypeScript types.
|
|
8
|
+
*
|
|
9
|
+
* Key capabilities:
|
|
10
|
+
* - **Parse**: Read headers and primitive blocks from `ArrayBuffer`, async iterables, or `ReadableStream`.
|
|
11
|
+
* - **Stream**: Use `TransformStream` helpers to process large files without buffering entirely in memory.
|
|
12
|
+
* - **Serialize**: Write header and primitive blocks back to spec-compliant blobs with size guardrails.
|
|
13
|
+
* - **Types**: Generated protobuf readers/writers and TypeScript interfaces for OSM data structures.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { readOsmPbf } from "@osmix/pbf"
|
|
18
|
+
*
|
|
19
|
+
* const { header, blocks } = await readOsmPbf(Bun.file('./monaco.pbf').stream())
|
|
20
|
+
* console.log(header.required_features)
|
|
21
|
+
*
|
|
22
|
+
* for await (const block of blocks) {
|
|
23
|
+
* console.log(block.primitivegroup.length, "groups")
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module @osmix/pbf
|
|
28
|
+
*/
|
|
29
|
+
export * from "./blobs-to-blocks";
|
|
30
|
+
export * from "./blocks-to-pbf";
|
|
31
|
+
export * from "./pbf-to-blobs";
|
|
32
|
+
export * from "./pbf-to-blocks";
|
|
33
|
+
export * from "./proto/fileformat";
|
|
34
|
+
export * from "./proto/osmformat";
|
|
35
|
+
export * from "./spec";
|
|
36
|
+
export * from "./utils";
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,cAAc,mBAAmB,CAAA;AACjC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @osmix/pbf - Low-level OSM PBF parsing and serialization.
|
|
3
|
+
*
|
|
4
|
+
* Provides streaming primitives for reading and writing OpenStreetMap PBF files
|
|
5
|
+
* using Web Streams and native compression APIs. Stays close to the official
|
|
6
|
+
* protobuf schema (`osmformat.proto`, `fileformat.proto`) while exposing
|
|
7
|
+
* predictable TypeScript types.
|
|
8
|
+
*
|
|
9
|
+
* Key capabilities:
|
|
10
|
+
* - **Parse**: Read headers and primitive blocks from `ArrayBuffer`, async iterables, or `ReadableStream`.
|
|
11
|
+
* - **Stream**: Use `TransformStream` helpers to process large files without buffering entirely in memory.
|
|
12
|
+
* - **Serialize**: Write header and primitive blocks back to spec-compliant blobs with size guardrails.
|
|
13
|
+
* - **Types**: Generated protobuf readers/writers and TypeScript interfaces for OSM data structures.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { readOsmPbf } from "@osmix/pbf"
|
|
18
|
+
*
|
|
19
|
+
* const { header, blocks } = await readOsmPbf(Bun.file('./monaco.pbf').stream())
|
|
20
|
+
* console.log(header.required_features)
|
|
21
|
+
*
|
|
22
|
+
* for await (const block of blocks) {
|
|
23
|
+
* console.log(block.primitivegroup.length, "groups")
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module @osmix/pbf
|
|
28
|
+
*/
|
|
29
|
+
export * from "./blobs-to-blocks";
|
|
30
|
+
export * from "./blocks-to-pbf";
|
|
31
|
+
export * from "./pbf-to-blobs";
|
|
32
|
+
export * from "./pbf-to-blocks";
|
|
33
|
+
export * from "./proto/fileformat";
|
|
34
|
+
export * from "./proto/osmformat";
|
|
35
|
+
export * from "./spec";
|
|
36
|
+
export * from "./utils";
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,cAAc,mBAAmB,CAAA;AACjC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a stateful parser that extracts compressed blobs from raw PBF bytes.
|
|
3
|
+
*
|
|
4
|
+
* OSM PBF files consist of length-prefixed blobs. This function returns a generator
|
|
5
|
+
* that accumulates incoming byte chunks and yields complete compressed blobs as they
|
|
6
|
+
* become available. The caller is responsible for decompression.
|
|
7
|
+
*
|
|
8
|
+
* The first yielded blob contains the file header; subsequent blobs contain primitive data.
|
|
9
|
+
*
|
|
10
|
+
* @returns A generator function that accepts byte chunks and yields compressed blob payloads.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { createOsmPbfBlobGenerator } from "@osmix/pbf"
|
|
15
|
+
*
|
|
16
|
+
* const generateBlobs = createOsmPbfBlobGenerator()
|
|
17
|
+
*
|
|
18
|
+
* for await (const chunk of stream) {
|
|
19
|
+
* for (const compressedBlob of generateBlobs(chunk)) {
|
|
20
|
+
* // Decompress and parse blob...
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function createOsmPbfBlobGenerator(): (chunk: Uint8Array) => Generator<Uint8Array<ArrayBuffer>, void, unknown>;
|
|
26
|
+
//# sourceMappingURL=pbf-to-blobs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pbf-to-blobs.d.ts","sourceRoot":"","sources":["../../src/pbf-to-blobs.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,yBAAyB,KAWb,OAAO,UAAU,uDAiC5C"}
|