@osmix/pbf 0.0.2 → 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.
Files changed (86) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +75 -82
  3. package/dist/src/blobs-to-blocks.d.ts +51 -3
  4. package/dist/src/blobs-to-blocks.d.ts.map +1 -1
  5. package/dist/src/blobs-to-blocks.js +60 -7
  6. package/dist/src/blobs-to-blocks.js.map +1 -1
  7. package/dist/src/blocks-to-pbf.d.ts +41 -5
  8. package/dist/src/blocks-to-pbf.d.ts.map +1 -1
  9. package/dist/src/blocks-to-pbf.js +41 -5
  10. package/dist/src/blocks-to-pbf.js.map +1 -1
  11. package/dist/src/index.d.ts +28 -0
  12. package/dist/src/index.d.ts.map +1 -1
  13. package/dist/src/index.js +28 -0
  14. package/dist/src/index.js.map +1 -1
  15. package/dist/src/pbf-to-blobs.d.ts +22 -3
  16. package/dist/src/pbf-to-blobs.d.ts.map +1 -1
  17. package/dist/src/pbf-to-blobs.js +24 -3
  18. package/dist/src/pbf-to-blobs.js.map +1 -1
  19. package/dist/src/pbf-to-blocks.d.ts +46 -4
  20. package/dist/src/pbf-to-blocks.d.ts.map +1 -1
  21. package/dist/src/pbf-to-blocks.js +46 -4
  22. package/dist/src/pbf-to-blocks.js.map +1 -1
  23. package/dist/src/utils.d.ts +0 -4
  24. package/dist/src/utils.d.ts.map +1 -1
  25. package/dist/src/utils.js +0 -32
  26. package/dist/src/utils.js.map +1 -1
  27. package/dist/test/blobs-to-blocks.test.js +22 -18
  28. package/dist/test/blobs-to-blocks.test.js.map +1 -1
  29. package/dist/test/pbf-to-blobs.test.js +24 -16
  30. package/dist/test/pbf-to-blobs.test.js.map +1 -1
  31. package/dist/test/read.bench.js +6 -4
  32. package/dist/test/read.bench.js.map +1 -1
  33. package/dist/test/read.test.js +5 -5
  34. package/dist/test/read.test.js.map +1 -1
  35. package/dist/test/streams.test.js +21 -13
  36. package/dist/test/streams.test.js.map +1 -1
  37. package/dist/test/utils.d.ts.map +1 -1
  38. package/dist/test/utils.js +8 -8
  39. package/dist/test/utils.js.map +1 -1
  40. package/dist/test/utils.test.js +8 -8
  41. package/dist/test/utils.test.js.map +1 -1
  42. package/dist/test/write.test.js +13 -8
  43. package/dist/test/write.test.js.map +1 -1
  44. package/package.json +6 -7
  45. package/src/blobs-to-blocks.ts +78 -7
  46. package/src/blocks-to-pbf.ts +42 -5
  47. package/src/index.ts +29 -0
  48. package/src/pbf-to-blobs.ts +24 -3
  49. package/src/pbf-to-blocks.ts +46 -4
  50. package/src/utils.ts +0 -29
  51. package/test/blobs-to-blocks.test.ts +25 -19
  52. package/test/pbf-to-blobs.test.ts +23 -17
  53. package/test/read.bench.ts +8 -4
  54. package/test/read.test.ts +5 -5
  55. package/test/streams.test.ts +22 -13
  56. package/test/utils.test.ts +8 -8
  57. package/test/utils.ts +8 -8
  58. package/test/write.test.ts +13 -8
  59. package/dist/blobs-to-blocks.d.ts +0 -5
  60. package/dist/blobs-to-blocks.js +0 -21
  61. package/dist/blocks-to-pbf.d.ts +0 -16
  62. package/dist/blocks-to-pbf.js +0 -73
  63. package/dist/index.d.ts +0 -8
  64. package/dist/index.js +0 -8
  65. package/dist/pbf-to-blobs.d.ts +0 -6
  66. package/dist/pbf-to-blobs.js +0 -48
  67. package/dist/pbf-to-blocks.d.ts +0 -20
  68. package/dist/pbf-to-blocks.js +0 -53
  69. package/dist/proto/fileformat.d.ts +0 -26
  70. package/dist/proto/fileformat.js +0 -56
  71. package/dist/proto/osmformat.d.ts +0 -91
  72. package/dist/proto/osmformat.js +0 -458
  73. package/dist/spec.d.ts +0 -5
  74. package/dist/spec.js +0 -9
  75. package/dist/test/utils.bun.test.d.ts +0 -2
  76. package/dist/test/utils.bun.test.d.ts.map +0 -1
  77. package/dist/test/utils.bun.test.js +0 -221
  78. package/dist/test/utils.bun.test.js.map +0 -1
  79. package/dist/test/verify-pbf-reading.bun.test.d.ts +0 -2
  80. package/dist/test/verify-pbf-reading.bun.test.d.ts.map +0 -1
  81. package/dist/test/verify-pbf-reading.bun.test.js +0 -32
  82. package/dist/test/verify-pbf-reading.bun.test.js.map +0 -1
  83. package/dist/utils.d.ts +0 -27
  84. package/dist/utils.js +0 -92
  85. package/test/utils.bun.test.ts +0 -277
  86. package/test/verify-pbf-reading.bun.test.ts +0 -39
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
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
+
3
9
  ## 0.0.2
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -1,19 +1,19 @@
1
1
  # @osmix/pbf
2
2
 
3
- @osmix/pbf is a low-level TypeScript toolkit for reading and writing OpenStreetMap PBF data. It keeps the API surface close to the official protobuf schema, surfaces predictable types, and runs in Node 20+ and modern browsers through Web Streams and native compression primitives.
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
- - Build streaming pipelines with `TransformStream` helpers instead of buffering entire files in memory.
9
- - Serialize header and primitive blocks back to spec-compliant blobs with size guardrails baked in.
10
- - Reuse generated protobuf types/readers so downstream tools can stay close to `osmformat.proto`.
11
- - Utility helpers handle compression, concatenation, and big-endian encoding tuned for the PBF format.
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
- npm install @osmix/pbf
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 response = await fetch("/fixtures/monaco.pbf")
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
- ### Stream as you go
39
+ ### Streaming with TransformStreams
41
40
 
42
- Use the streaming helpers when you do not want to materialize the whole file.
41
+ For large files, use `TransformStream` helpers to process data incrementally:
43
42
 
44
43
  ```ts
45
- import { OsmPbfBytesToBlocksTransformStream } from "@osmix/pbf"
44
+ import {
45
+ OsmPbfBytesToBlocksTransformStream,
46
+ OsmBlocksToPbfBytesTransformStream,
47
+ } from "@osmix/pbf"
46
48
 
47
- const response = await fetch("/fixtures/monaco.pbf")
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
- ### Write blocks back to PBF
66
-
67
- Serialize individual blocks into blobs, or stream them directly to a writable target.
53
+ // Encode blocks back to PBF bytes
54
+ const pbfStream = blocksStream
55
+ .pipeThrough(new OsmBlocksToPbfBytesTransformStream())
56
+ ```
68
57
 
69
- #### Buffer the result
58
+ ### Write a PBF file
70
59
 
71
60
  ```ts
72
- import { concatUint8, osmBlockToPbfBlobBytes, readOsmPbf } from "@osmix/pbf"
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
- const fullFile = concatUint8(...chunks)
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
- #### Stream to a sink
73
+ ## API
85
74
 
86
- Generators returned by `readOsmPbf` are single-use. Re-open the source (or buffer the blocks) if you want to stream the same dataset again.
75
+ ### Reading
87
76
 
88
- ```ts
89
- import { OsmBlocksToPbfBytesTransformStream, readOsmPbf } from "@osmix/pbf"
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
- const response = await fetch("/fixtures/monaco.pbf")
92
- const { header, blocks } = await readOsmPbf(response.body)
86
+ ### Writing
93
87
 
94
- const upstream = new ReadableStream({
95
- async start(controller) {
96
- controller.enqueue(header)
97
- for await (const block of blocks) controller.enqueue(block)
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
- await upstream
103
- .pipeThrough(new OsmBlocksToPbfBytesTransformStream())
104
- .pipeTo(new WritableStream({ write: persistChunk }))
105
- ```
93
+ ### Types
106
94
 
107
- `persistChunk` represents your storage layer (filesystem writes, uploads, IndexedDB, and so on). It receives `Uint8Array` pieces in the order they should be persisted.
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
- ## API overview
103
+ ### Constants
110
104
 
111
- - `readOsmPbf(data)` Parses binary PBF data, returning `{ header, blocks }`. Throws if the first block is not an OSM header.
112
- - `OsmPbfBytesToBlocksTransformStream` – Web `TransformStream` that emits the header once and then primitive blocks as they become available.
113
- - `OsmBlocksToPbfBytesTransformStream` Inverse transform that turns header/primitive blocks into PBF byte blobs while enforcing size limits.
114
- - `createOsmPbfBlobGenerator()` Returns a stateful generator that slices incoming bytes into compressed blob payloads (`Uint8Array`s), emitting the header blob first.
115
- - `osmPbfBlobsToBlocksGenerator(blobs)` Accepts a (async) generator of compressed blobs, decompresses them, and yields the header followed by primitive blocks.
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
- ## See also
111
+ ## Related Packages
121
112
 
122
- - [`@osmix/json`](../json/README.md) – Converts parsed blocks into ergonomic JSON or GeoJSON entities.
123
- - [`@osmix/core`](../core/README.md) – Uses these readers/writers for ingest and export workflows.
124
- - [`@osmix/change`](../change/README.md) – Builds on `@osmix/core` to generate change pipelines.
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 limitations
117
+ ## Environment and Limitations
127
118
 
128
- - Requires runtimes with Web Streams + `CompressionStream` / `DecompressionStream` support (modern browsers, Node 20+).
129
- - Only `zlib_data` blobs are supported today; files containing `raw` or `lzma` payloads will throw.
130
- - When working with Node `Readable` / `Writable` streams, adapt them to Web Streams (`stream/web`) before passing them to these helpers.
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 usage guidance
123
+ ### Memory Guidance
133
124
 
134
- - Prefer streaming transforms (`OsmPbfBytesToBlocksTransformStream` → `OsmBlocksToPbfBytesTransformStream`) for large extracts to avoid materializing entire files.
135
- - Re-materializing full files (e.g., concatenating all blocks into one buffer) can require memory roughly proportional to input size plus transient compression buffers.
136
- - In browsers, keep an eye on available heap limits (2–4 GB typical). Use chunked persistence (IndexedDB, file streams) rather than holding all bytes in RAM.
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
- - `bun run test packages/pbf`
141
- - `bun run lint packages/pbf`
142
- - `bun run typecheck packages/pbf`
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.
@@ -1,6 +1,54 @@
1
1
  /**
2
- * Decompresses raw OSM PBF blobs and yields typed header and primitive blocks.
3
- * Expects the first blob to contain the file header and streams the rest as data blocks.
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
4
8
  */
5
- export declare function osmPbfBlobsToBlocksGenerator(blobs: AsyncGenerator<Uint8Array<ArrayBuffer>> | Generator<Uint8Array<ArrayBuffer>>, decompress?: (data: Uint8Array<ArrayBuffer>) => Promise<Uint8Array<ArrayBuffer>>): AsyncGenerator<import(".").OsmPbfHeaderBlock | import(".").OsmPbfBlock, void, unknown>;
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>;
6
54
  //# sourceMappingURL=blobs-to-blocks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"blobs-to-blocks.d.ts","sourceRoot":"","sources":["../../src/blobs-to-blocks.ts"],"names":[],"mappings":"AAIA;;;GAGG;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,0FAarD"}
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"}
@@ -1,22 +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
+ */
1
9
  import Pbf from "pbf";
2
- import { readHeaderBlock, readPrimitiveBlock } from "./proto/osmformat";
10
+ import { readHeaderBlock, readPrimitiveBlock, } from "./proto/osmformat";
3
11
  import { webDecompress } from "./utils";
4
12
  /**
5
- * Decompresses raw OSM PBF blobs and yields typed header and primitive blocks.
6
- * Expects the first blob to contain the file header and streams the rest as data blocks.
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
+ * ```
7
38
  */
8
39
  export async function* osmPbfBlobsToBlocksGenerator(blobs, decompress = webDecompress) {
9
40
  let headerRead = false;
10
41
  for await (const blob of blobs) {
11
- const decompressedBlob = await decompress(blob);
12
- const pbf = new Pbf(decompressedBlob);
13
42
  if (!headerRead) {
14
43
  headerRead = true;
15
- yield readHeaderBlock(pbf);
44
+ yield readOsmHeaderBlock(blob, decompress);
16
45
  }
17
46
  else {
18
- yield readPrimitiveBlock(pbf);
47
+ yield readOsmPrimitiveBlock(blob, decompress);
19
48
  }
20
49
  }
21
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
+ }
22
75
  //# sourceMappingURL=blobs-to-blocks.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"blobs-to-blocks.js","sourceRoot":"","sources":["../../src/blobs-to-blocks.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAEvC;;;GAGG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,4BAA4B,CAClD,KAEqC,EACrC,aAEwC,aAAa;IAErD,IAAI,UAAU,GAAG,KAAK,CAAA;IACtB,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAChC,MAAM,gBAAgB,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,CAAA;QAC/C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,gBAAgB,CAAC,CAAA;QACrC,IAAI,CAAC,UAAU,EAAE,CAAC;YACjB,UAAU,GAAG,IAAI,CAAA;YACjB,MAAM,eAAe,CAAC,GAAG,CAAC,CAAA;QAC3B,CAAC;aAAM,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,GAAG,IAAI,GAAG,CAAC,gBAAgB,CAAC,CAAA;IACrC,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAA;AAC/B,CAAC"}
@@ -1,14 +1,50 @@
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 type { OsmPbfBlock, OsmPbfHeaderBlock } from "./proto/osmformat";
2
10
  /**
3
- * Serializes a header or primitive block into a spec-compliant compressed blob.
4
- * Automatically sets the blob type, compresses the payload, and enforces size guardrails.
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
+ *
5
17
  * @param block - Parsed header or primitive block to encode.
6
- * @returns BlobHeader length prefix + Blob bytes as a single Uint8Array.
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
+ * ```
7
31
  */
8
32
  export declare function osmBlockToPbfBlobBytes(block: OsmPbfBlock | OsmPbfHeaderBlock, compress?: (data: Uint8Array<ArrayBuffer>) => Promise<Uint8Array<ArrayBuffer>>): Promise<Uint8Array<ArrayBufferLike>>;
9
33
  /**
10
- * Web `TransformStream` that converts OSM header/data blocks into PBF byte chunks.
11
- * Throws if the header is not the first block and reuses `osmBlockToPbfBlobBytes` for encoding.
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
+ * ```
12
48
  */
13
49
  export declare class OsmBlocksToPbfBytesTransformStream extends TransformStream<OsmPbfHeaderBlock | OsmPbfBlock, Uint8Array> {
14
50
  headerEnqueued: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"blocks-to-pbf.d.ts","sourceRoot":"","sources":["../../src/blocks-to-pbf.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAUvE;;;;;GAKG;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;;;GAGG;AACH,qBAAa,kCAAmC,SAAQ,eAAe,CACtE,iBAAiB,GAAG,WAAW,EAC/B,UAAU,CACV;IACA,cAAc,UAAQ;;CAYtB"}
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,13 +1,37 @@
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
13
  import { concatUint8, uint32BE, webCompress } from "./utils";
6
14
  /**
7
- * Serializes a header or primitive block into a spec-compliant compressed blob.
8
- * Automatically sets the blob type, compresses the payload, and enforces size guardrails.
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
- * @returns BlobHeader length prefix + Blob bytes as a single Uint8Array.
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
36
  export async function osmBlockToPbfBlobBytes(block, compress = webCompress) {
13
37
  const contentPbf = new Pbf();
@@ -54,8 +78,20 @@ export async function osmBlockToPbfBlobBytes(block, compress = webCompress) {
54
78
  return concatUint8(blobHeaderSize, blobHeader, blob);
55
79
  }
56
80
  /**
57
- * Web `TransformStream` that converts OSM header/data blocks into PBF byte chunks.
58
- * Throws if the header is not the first block and reuses `osmBlockToPbfBlobBytes` for encoding.
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;
@@ -1 +1 @@
1
- {"version":3,"file":"blocks-to-pbf.js","sourceRoot":"","sources":["../../src/blocks-to-pbf.ts"],"names":[],"mappings":"AAAA,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,QAAQ,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE5D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC3C,KAAsC,EACtC,WAEwC,WAAW;IAEnD,MAAM,UAAU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,MAAM,sBAAsB,CAAC,KAAK,CAAC,CAAC,CAAA;YACxD,CAAC;SACD,CAAC,CAAA;IACH,CAAC;CACD"}
@@ -1,3 +1,31 @@
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
+ */
1
29
  export * from "./blobs-to-blocks";
2
30
  export * from "./blocks-to-pbf";
3
31
  export * from "./pbf-to-blobs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,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"}
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"}
package/dist/src/index.js CHANGED
@@ -1,3 +1,31 @@
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
+ */
1
29
  export * from "./blobs-to-blocks";
2
30
  export * from "./blocks-to-pbf";
3
31
  export * from "./pbf-to-blobs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,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"}
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"}
@@ -1,7 +1,26 @@
1
1
  /**
2
- * Creates a stateful parser that slices incoming bytes into compressed OSM PBF blobs.
3
- * Works with buffers, iterables, or streams and yields `Uint8Array` payloads ready to decompress.
4
- * The first blob represents the file header; subsequent blobs hold primitive data.
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
+ * ```
5
24
  */
6
25
  export declare function createOsmPbfBlobGenerator(): (chunk: Uint8Array) => Generator<Uint8Array<ArrayBuffer>, void, unknown>;
7
26
  //# sourceMappingURL=pbf-to-blobs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pbf-to-blobs.d.ts","sourceRoot":"","sources":["../../src/pbf-to-blobs.ts"],"names":[],"mappings":"AAQA;;;;GAIG;AACH,wBAAgB,yBAAyB,KASb,OAAO,UAAU,uDAiC5C"}
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"}