@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
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../test/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAE7D,OAAO,KAAK,EACX,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,MAAM,wBAAwB,CAAA;AAE/B,wBAAsB,gBAAgB,CACrC,GAAG,EAAE;IACJ,MAAM,EAAE,iBAAiB,CAAA;IACzB,MAAM,EAAE,cAAc,CAAC,WAAW,CAAC,CAAA;CACnC,EACD,GAAG,EAAE,UAAU;;;;;;;GAgBf;AAED,wBAAgB,sBAAsB;qBAUb,WAAW;;;;;;;;;EAuBnC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../test/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAC7D,OAAO,KAAK,EACX,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,MAAM,wBAAwB,CAAA;AAE/B,wBAAsB,gBAAgB,CACrC,GAAG,EAAE;IACJ,MAAM,EAAE,iBAAiB,CAAA;IACzB,MAAM,EAAE,cAAc,CAAC,WAAW,CAAC,CAAA;CACnC,EACD,GAAG,EAAE,UAAU;;;;;;;GAgBf;AAED,wBAAgB,sBAAsB;qBAUb,WAAW;;;;;;;;;EAuBnC"}
@@ -1,16 +1,16 @@
1
- import { assert } from "vitest";
1
+ import { expect } from "bun:test";
2
2
  export async function testOsmPbfReader(osm, pbf) {
3
- assert.deepEqual(osm.header.bbox, pbf.bbox);
3
+ expect(osm.header.bbox).toEqual(pbf.bbox);
4
4
  const { onGroup, count } = createOsmEntityCounter();
5
5
  for await (const block of osm.blocks)
6
6
  for (const group of block.primitivegroup)
7
7
  onGroup(group);
8
- assert.equal(count.nodes, pbf.nodes);
9
- assert.equal(count.ways, pbf.ways);
10
- assert.equal(count.relations, pbf.relations);
11
- assert.equal(count.node0, pbf.node0.id);
12
- assert.equal(count.way0, pbf.way0);
13
- assert.equal(count.relation0, pbf.relation0);
8
+ expect(count.nodes).toBe(pbf.nodes);
9
+ expect(count.ways).toBe(pbf.ways);
10
+ expect(count.relations).toBe(pbf.relations);
11
+ expect(count.node0).toBe(pbf.node0.id);
12
+ expect(count.way0).toBe(pbf.way0);
13
+ expect(count.relation0).toBe(pbf.relation0);
14
14
  return count;
15
15
  }
16
16
  export function createOsmEntityCounter() {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../test/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAO/B,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACrC,GAGC,EACD,GAAe;IAEf,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,CAAA;IAE3C,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,sBAAsB,EAAE,CAAA;IACnD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,CAAC,MAAM;QACnC,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,cAAc;YAAE,OAAO,CAAC,KAAK,CAAC,CAAA;IAEzD,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,CAAA;IACpC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,CAAA;IAClC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS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AAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;QACxC,CAAC;QAED,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,CAAA;QACvC,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YACjB,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAA;QACrC,CAAC;QACD,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC,CAAA;QACrC,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,SAAS,EAAE,MAAM,IAAI,CAAC,CAAA;IAChD,CAAC,CAAA;IAED,OAAO;QACN,OAAO;QACP,KAAK;KACL,CAAA;AACF,CAAC"}
@@ -1,12 +1,12 @@
1
- import { assert, describe, expect, it } from "vitest";
1
+ import { describe, expect, it } from "bun:test";
2
2
  import { concatUint8, toAsyncGenerator, uint32BE, webCompress, webDecompress, } from "../src/utils";
3
3
  describe("utils", () => {
4
4
  it("wraps values into an async generator", async () => {
5
5
  const generator = toAsyncGenerator(3);
6
6
  const first = await generator.next();
7
- assert.deepEqual(first, { value: 3, done: false });
7
+ expect(first).toEqual({ value: 3, done: false });
8
8
  const done = await generator.next();
9
- assert.deepEqual(done, { value: undefined, done: true });
9
+ expect(done).toEqual({ value: undefined, done: true });
10
10
  });
11
11
  it("consumes readable streams", async () => {
12
12
  const stream = new ReadableStream({
@@ -19,7 +19,7 @@ describe("utils", () => {
19
19
  const values = [];
20
20
  for await (const value of toAsyncGenerator(stream))
21
21
  values.push(value);
22
- assert.deepEqual(values, [1, 2]);
22
+ expect(values).toEqual([1, 2]);
23
23
  });
24
24
  it("throws on nullish inputs", async () => {
25
25
  const invalidInput = null;
@@ -28,17 +28,17 @@ describe("utils", () => {
28
28
  it("concatenates Uint8Array segments", () => {
29
29
  const a = Uint8Array.of(1, 2);
30
30
  const b = Uint8Array.of(3);
31
- assert.deepEqual(concatUint8(a, b), Uint8Array.of(1, 2, 3));
31
+ expect(concatUint8(a, b)).toEqual(Uint8Array.of(1, 2, 3));
32
32
  });
33
33
  it("encodes big-endian 32-bit integers", () => {
34
- assert.deepEqual(uint32BE(0x01020304), Uint8Array.of(1, 2, 3, 4));
34
+ expect(uint32BE(0x01020304)).toEqual(Uint8Array.of(1, 2, 3, 4));
35
35
  });
36
36
  it("compresses and decompresses data", async () => {
37
37
  const input = new TextEncoder().encode("osmix");
38
38
  const compressed = await webCompress(input);
39
- assert.notDeepEqual(compressed, input);
39
+ expect(compressed).not.toEqual(input);
40
40
  const decompressed = await webDecompress(compressed);
41
- assert.deepEqual(decompressed, input);
41
+ expect(decompressed).toEqual(input);
42
42
  });
43
43
  });
44
44
  //# sourceMappingURL=utils.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.test.js","sourceRoot":"","sources":["../../test/utils.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AACrD,OAAO,EACN,WAAW,EACX,gBAAgB,EAChB,QAAQ,EACR,WAAW,EACX,aAAa,GACb,MAAM,cAAc,CAAA;AAErB,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACtB,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;QACrD,MAAM,SAAS,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAA;QACrC,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,CAAA;QACpC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;QAClD,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,CAAA;QACnC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAA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CAAC,CAAA;IAC1D,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC7C,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAChE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,kCAAkC,EAAE,KAAK,IAAI,EAAE;QACjD,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAA4B,CAAA;QAC1E,MAAM,UAAU,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,CAAA;QAC3C,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QACrC,MAAM,YAAY,GAAG,MAAM,aAAa,CAAC,UAAU,CAAC,CAAA;QACpD,MAAM,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
@@ -1,6 +1,6 @@
1
+ import { describe, expect, it } from "bun:test";
1
2
  import { unlink } from "node:fs/promises";
2
3
  import { getFixtureFile, getFixtureFileReadStream, getFixtureFileWriteStream, getFixturePath, PBFs, } from "@osmix/shared/test/fixtures";
3
- import { assert, describe, it } from "vitest";
4
4
  import { OsmBlocksToPbfBytesTransformStream, osmBlockToPbfBlobBytes, } from "../src/blocks-to-pbf";
5
5
  import { OsmPbfBytesToBlocksTransformStream, readOsmPbf, } from "../src/pbf-to-blocks";
6
6
  import { testOsmPbfReader } from "./utils";
@@ -36,14 +36,19 @@ describe("write", () => {
36
36
  write(await osmBlockToPbfBlobBytes(block));
37
37
  }
38
38
  // Re-parse the new PBF and test
39
- assert.exists(data.buffer);
40
- // TODO: assert.equal(stream.buffer.byteLength, fileData.byteLength)
39
+ expect(data.buffer).toBeDefined();
40
+ // Note: We don't assert byte-level equality because the written PBF may have
41
+ // different compression, block ordering, or encoding than the original file.
42
+ // Semantic equivalence (verified by parsing and comparing entities) is more meaningful.
41
43
  const osm2 = await readOsmPbf(data);
42
- assert.deepEqual(osm.header, osm2.header);
44
+ expect(osm.header).toEqual(osm2.header);
43
45
  const entities = await testOsmPbfReader(osm2, pbf);
44
- assert.equal(entities.node0, node0);
45
- assert.equal(entities.way0, way0);
46
- assert.equal(entities.relation0, relation0);
46
+ if (node0 === null || way0 === null || relation0 === null) {
47
+ throw new Error("Expected node0, way0, and relation0 to be set");
48
+ }
49
+ expect(entities.node0).toBe(node0);
50
+ expect(entities.way0).toBe(way0);
51
+ expect(entities.relation0).toBe(relation0);
47
52
  });
48
53
  it("to file", async () => {
49
54
  const testFileName = `${name}-write-test.pbf`;
@@ -55,7 +60,7 @@ describe("write", () => {
55
60
  .pipeTo(fileWriteStream);
56
61
  const testFileData = await getFixtureFile(pbf.url);
57
62
  const testOsm = await readOsmPbf(testFileData);
58
- assert.deepEqual(testOsm.header.bbox, pbf.bbox);
63
+ expect(testOsm.header.bbox).toEqual(pbf.bbox);
59
64
  await testOsmPbfReader(testOsm, pbf);
60
65
  await unlink(getFixturePath(testFileName));
61
66
  });
@@ -1 +1 @@
1
- {"version":3,"file":"write.test.js","sourceRoot":"","sources":["../../test/write.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EACN,cAAc,EACd,wBAAwB,EACxB,yBAAyB,EACzB,cAAc,EACd,IAAI,GACJ,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,EACN,kCAAkC,EAClC,sBAAsB,GACtB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACN,kCAAkC,EAClC,UAAU,GACV,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,gBAAg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AC,CAAA;QAEF,EAAE,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE;YACxB,MAAM,YAAY,GAAG,GAAG,IAAI,iBAAiB,CAAA;YAC7C,MAAM,UAAU,GAAG,wBAAwB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAEpD,MAAM,eAAe,GAAG,yBAAyB,CAAC,YAAY,CAAC,CAAA;YAC/D,MAAM,UAAU;iBACd,WAAW,CAAC,IAAI,kCAAkC,EAAE,CAAC;iBACrD,WAAW,CAAC,IAAI,kCAAkC,EAAE,CAAC;iBACrD,MAAM,CAAC,eAAe,CAAC,CAAA;YAEzB,MAAM,YAAY,GAAG,MAAM,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAClD,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,YAAY,CAAC,CAAA;YAE9C,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;YAC7C,MAAM,gBAAgB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;YAEpC,MAAM,MAAM,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAA;QAC3C,CAAC,CAAC,CAAA;IACH,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@osmix/pbf",
4
4
  "description": "A low level, modern, runtime agnostic OSM PBF parser and writer written in TypeScript.",
5
- "version": "0.0.2",
5
+ "version": "0.0.3",
6
6
  "type": "module",
7
7
  "main": "./src/index.ts",
8
8
  "publishConfig": {
@@ -32,17 +32,16 @@
32
32
  },
33
33
  "sideEffects": false,
34
34
  "scripts": {
35
- "bench": "vitest bench",
35
+ "bench": "bun test --bench",
36
36
  "build": "tsc",
37
37
  "prepublishOnly": "tsc",
38
- "test": "vitest",
39
- "typecheck": "tsc --noEmit"
38
+ "test": "bun test",
39
+ "typecheck": "tsgo --noEmit"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@osmix/shared": "workspace:*",
43
- "@types/node": "catalog:",
44
- "typescript": "catalog:",
45
- "vitest": "catalog:"
43
+ "@types/bun": "catalog:",
44
+ "typescript": "catalog:"
46
45
  },
47
46
  "dependencies": {
48
47
  "pbf": "catalog:"
@@ -1,10 +1,47 @@
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
+
1
10
  import Pbf from "pbf"
2
- import { readHeaderBlock, readPrimitiveBlock } from "./proto/osmformat"
11
+ import {
12
+ type OsmPbfBlock,
13
+ type OsmPbfHeaderBlock,
14
+ readHeaderBlock,
15
+ readPrimitiveBlock,
16
+ } from "./proto/osmformat"
3
17
  import { webDecompress } from "./utils"
4
18
 
5
19
  /**
6
- * Decompresses raw OSM PBF blobs and yields typed header and primitive blocks.
7
- * Expects the first blob to contain the file header and streams the rest as data blocks.
20
+ * Decompress and decode a stream of raw PBF blobs into typed blocks.
21
+ *
22
+ * This async generator handles the transition from compressed bytes to parsed
23
+ * protobuf structures. The first blob is always decoded as a header block;
24
+ * subsequent blobs are decoded as primitive blocks containing OSM entities.
25
+ *
26
+ * @param blobs - Async or sync generator yielding compressed blob payloads.
27
+ * @param decompress - Optional decompression function (defaults to Web Streams zlib).
28
+ * @yields Header block first, then primitive blocks.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { osmPbfBlobsToBlocksGenerator, createOsmPbfBlobGenerator } from "@osmix/pbf"
33
+ *
34
+ * const generateBlobs = createOsmPbfBlobGenerator()
35
+ * const blobsGen = (async function* () {
36
+ * for await (const chunk of stream) {
37
+ * yield* generateBlobs(chunk)
38
+ * }
39
+ * })()
40
+ *
41
+ * for await (const block of osmPbfBlobsToBlocksGenerator(blobsGen)) {
42
+ * // First iteration yields header, rest yield primitive blocks
43
+ * }
44
+ * ```
8
45
  */
9
46
  export async function* osmPbfBlobsToBlocksGenerator(
10
47
  blobs:
@@ -16,13 +53,47 @@ export async function* osmPbfBlobsToBlocksGenerator(
16
53
  ) {
17
54
  let headerRead = false
18
55
  for await (const blob of blobs) {
19
- const decompressedBlob = await decompress(blob)
20
- const pbf = new Pbf(decompressedBlob)
21
56
  if (!headerRead) {
22
57
  headerRead = true
23
- yield readHeaderBlock(pbf)
58
+ yield readOsmHeaderBlock(blob, decompress)
24
59
  } else {
25
- yield readPrimitiveBlock(pbf)
60
+ yield readOsmPrimitiveBlock(blob, decompress)
26
61
  }
27
62
  }
28
63
  }
64
+
65
+ /**
66
+ * Decompress and parse a header block from a compressed blob.
67
+ *
68
+ * @param compressedBlob - Zlib-compressed protobuf header blob.
69
+ * @param decompress - Optional decompression function.
70
+ * @returns Parsed header block with required/optional features and bbox.
71
+ */
72
+ export async function readOsmHeaderBlock(
73
+ compressedBlob: Uint8Array<ArrayBuffer>,
74
+ decompress: (
75
+ data: Uint8Array<ArrayBuffer>,
76
+ ) => Promise<Uint8Array<ArrayBuffer>> = webDecompress,
77
+ ): Promise<OsmPbfHeaderBlock> {
78
+ const decompressedBlob = await decompress(compressedBlob)
79
+ const pbf = new Pbf(decompressedBlob)
80
+ return readHeaderBlock(pbf)
81
+ }
82
+
83
+ /**
84
+ * Decompress and parse a primitive block from a compressed blob.
85
+ *
86
+ * @param compressedBlob - Zlib-compressed protobuf primitive blob.
87
+ * @param decompress - Optional decompression function.
88
+ * @returns Parsed primitive block with string table and primitive groups.
89
+ */
90
+ export async function readOsmPrimitiveBlock(
91
+ compressedBlob: Uint8Array<ArrayBuffer>,
92
+ decompress: (
93
+ data: Uint8Array<ArrayBuffer>,
94
+ ) => Promise<Uint8Array<ArrayBuffer>> = webDecompress,
95
+ ): Promise<OsmPbfBlock> {
96
+ const decompressedBlob = await decompress(compressedBlob)
97
+ const pbf = new Pbf(decompressedBlob)
98
+ return readPrimitiveBlock(pbf)
99
+ }
@@ -1,3 +1,12 @@
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
+ */
9
+
1
10
  import Pbf from "pbf"
2
11
  import { writeBlob, writeBlobHeader } from "./proto/fileformat"
3
12
  import type { OsmPbfBlock, OsmPbfHeaderBlock } from "./proto/osmformat"
@@ -11,10 +20,26 @@ import {
11
20
  import { concatUint8, uint32BE, webCompress } from "./utils"
12
21
 
13
22
  /**
14
- * Serializes a header or primitive block into a spec-compliant compressed blob.
15
- * Automatically sets the blob type, compresses the payload, and enforces size guardrails.
23
+ * Serialize a header or primitive block into spec-compliant PBF bytes.
24
+ *
25
+ * Handles protobuf encoding, zlib compression, blob wrapping, and length prefixing.
26
+ * Validates output against OSM PBF specification size limits and logs warnings
27
+ * if recommended sizes are exceeded.
28
+ *
16
29
  * @param block - Parsed header or primitive block to encode.
17
- * @returns BlobHeader length prefix + Blob bytes as a single Uint8Array.
30
+ * @param compress - Optional compression function (defaults to Web Streams zlib).
31
+ * @returns Complete blob bytes: 4-byte length prefix + BlobHeader + Blob.
32
+ * @throws If blob exceeds maximum size limits (64 KiB header, 32 MiB data).
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { osmBlockToPbfBlobBytes } from "@osmix/pbf"
37
+ *
38
+ * const headerBytes = await osmBlockToPbfBlobBytes({
39
+ * required_features: ["OsmSchema-V0.6", "DenseNodes"],
40
+ * optional_features: [],
41
+ * })
42
+ * ```
18
43
  */
19
44
  export async function osmBlockToPbfBlobBytes(
20
45
  block: OsmPbfBlock | OsmPbfHeaderBlock,
@@ -76,8 +101,20 @@ export async function osmBlockToPbfBlobBytes(
76
101
  }
77
102
 
78
103
  /**
79
- * Web `TransformStream` that converts OSM header/data blocks into PBF byte chunks.
80
- * Throws if the header is not the first block and reuses `osmBlockToPbfBlobBytes` for encoding.
104
+ * Web `TransformStream` that encodes OSM blocks into PBF byte chunks.
105
+ *
106
+ * Accepts a stream of header and primitive blocks and outputs spec-compliant
107
+ * PBF bytes. The header block must be the first item in the stream.
108
+ *
109
+ * @throws If a primitive block is received before the header.
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * import { OsmBlocksToPbfBytesTransformStream } from "@osmix/pbf"
114
+ *
115
+ * const pbfStream = blocksStream.pipeThrough(new OsmBlocksToPbfBytesTransformStream())
116
+ * await pbfStream.pipeTo(writableFile)
117
+ * ```
81
118
  */
82
119
  export class OsmBlocksToPbfBytesTransformStream extends TransformStream<
83
120
  OsmPbfHeaderBlock | OsmPbfBlock,
package/src/index.ts CHANGED
@@ -1,3 +1,32 @@
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
+
1
30
  export * from "./blobs-to-blocks"
2
31
  export * from "./blocks-to-pbf"
3
32
  export * from "./pbf-to-blobs"
@@ -7,9 +7,28 @@ import {
7
7
  } from "./proto/fileformat"
8
8
 
9
9
  /**
10
- * Creates a stateful parser that slices incoming bytes into compressed OSM PBF blobs.
11
- * Works with buffers, iterables, or streams and yields `Uint8Array` payloads ready to decompress.
12
- * The first blob represents the file header; subsequent blobs hold primitive data.
10
+ * Create a stateful parser that extracts compressed blobs from raw PBF bytes.
11
+ *
12
+ * OSM PBF files consist of length-prefixed blobs. This function returns a generator
13
+ * that accumulates incoming byte chunks and yields complete compressed blobs as they
14
+ * become available. The caller is responsible for decompression.
15
+ *
16
+ * The first yielded blob contains the file header; subsequent blobs contain primitive data.
17
+ *
18
+ * @returns A generator function that accepts byte chunks and yields compressed blob payloads.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { createOsmPbfBlobGenerator } from "@osmix/pbf"
23
+ *
24
+ * const generateBlobs = createOsmPbfBlobGenerator()
25
+ *
26
+ * for await (const chunk of stream) {
27
+ * for (const compressedBlob of generateBlobs(chunk)) {
28
+ * // Decompress and parse blob...
29
+ * }
30
+ * }
31
+ * ```
13
32
  */
14
33
  export function createOsmPbfBlobGenerator() {
15
34
  let pbf: Pbf = new Pbf(new Uint8Array(0))
@@ -19,6 +38,8 @@ export function createOsmPbfBlobGenerator() {
19
38
 
20
39
  /**
21
40
  * Feed the parser with the next chunk of bytes and yield any complete compressed blobs.
41
+ * @param chunk - Raw bytes from the PBF file.
42
+ * @yields Compressed blob payloads (zlib-compressed protobuf data).
22
43
  */
23
44
  return function* nextChunk(chunk: Uint8Array) {
24
45
  const currentBuffer: Uint8Array = pbf.buf.slice(pbf.pos)
@@ -13,11 +13,37 @@ import {
13
13
  webDecompress,
14
14
  } from "./utils"
15
15
 
16
+ /** Number of bytes used to encode the BlobHeader length prefix (big-endian uint32). */
16
17
  export const HEADER_LENGTH_BYTES = 4
17
18
 
18
19
  /**
19
- * Parses OSM PBF bytes from buffers, streams, or generators into header + block iterators.
20
- * Returns the decoded header and a lazy async generator of primitive blocks.
20
+ * Parse an OSM PBF file from various input sources.
21
+ *
22
+ * Accepts `ArrayBuffer`, `Uint8Array`, `ReadableStream<Uint8Array>`, or async generators.
23
+ * Returns the file header and a lazy async generator of primitive blocks for on-demand parsing.
24
+ *
25
+ * @param data - PBF bytes as buffer, stream, or async iterable.
26
+ * @returns Object with `header` (file metadata) and `blocks` (async generator of primitive blocks).
27
+ * @throws If the header block is missing or malformed.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { readOsmPbf } from "@osmix/pbf"
32
+ *
33
+ * // From a file stream
34
+ * const { header, blocks } = await readOsmPbf(Bun.file('./monaco.pbf').stream())
35
+ *
36
+ * // From a fetch response
37
+ * const response = await fetch('/data/monaco.pbf')
38
+ * const { header, blocks } = await readOsmPbf(response.body!)
39
+ *
40
+ * // Iterate blocks lazily
41
+ * for await (const block of blocks) {
42
+ * for (const group of block.primitivegroup) {
43
+ * console.log(group.dense?.id.length ?? 0, "dense nodes")
44
+ * }
45
+ * }
46
+ * ```
21
47
  */
22
48
  export async function readOsmPbf(
23
49
  data: AsyncGeneratorValue<Uint8Array<ArrayBufferLike>>,
@@ -43,8 +69,24 @@ export async function readOsmPbf(
43
69
  }
44
70
 
45
71
  /**
46
- * Web `TransformStream` that turns raw PBF byte chunks into OSM header/data blocks.
47
- * Assumes the first decoded blob carries the header and emits it before any primitive blocks.
72
+ * Web `TransformStream` that decodes raw PBF byte chunks into OSM header and data blocks.
73
+ *
74
+ * The first blob in an OSM PBF file is always the header block; subsequent blobs
75
+ * contain primitive data (nodes, ways, relations). This stream handles the framing,
76
+ * decompression, and protobuf decoding automatically.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * import { OsmPbfBytesToBlocksTransformStream } from "@osmix/pbf"
81
+ *
82
+ * const response = await fetch('/data/monaco.pbf')
83
+ * const blocksStream = response.body!
84
+ * .pipeThrough(new OsmPbfBytesToBlocksTransformStream())
85
+ *
86
+ * const reader = blocksStream.getReader()
87
+ * const { value: header } = await reader.read() // First read yields header
88
+ * // Subsequent reads yield primitive blocks
89
+ * ```
48
90
  */
49
91
  export class OsmPbfBytesToBlocksTransformStream extends TransformStream<
50
92
  Uint8Array<ArrayBufferLike>,
package/src/utils.ts CHANGED
@@ -38,30 +38,12 @@ export async function* toAsyncGenerator<T>(
38
38
  }
39
39
  }
40
40
 
41
- /**
42
- * Returns true when executing inside the Bun runtime.
43
- */
44
- export function isBun(): boolean {
45
- return "Bun" in globalThis
46
- }
47
-
48
41
  /**
49
42
  * Web decompression stream
50
43
  */
51
44
  export async function webDecompress(
52
45
  data: Uint8Array<ArrayBuffer>,
53
46
  ): Promise<Uint8Array<ArrayBuffer>> {
54
- if (isBun()) {
55
- // @ts-ignore Only used in Bun runtime.
56
- const { inflate } = await import("node:zlib")
57
- const result = await new Promise<Uint8Array>((resolve, reject) => {
58
- inflate(data, (error: unknown, result: Uint8Array) => {
59
- if (error) reject(error)
60
- else resolve(new Uint8Array(result))
61
- })
62
- })
63
- return result as unknown as Uint8Array<ArrayBuffer>
64
- }
65
47
  return transformBytes(data, new DecompressionStream("deflate"))
66
48
  }
67
49
 
@@ -71,17 +53,6 @@ export async function webDecompress(
71
53
  export async function webCompress(
72
54
  data: Uint8Array<ArrayBuffer>,
73
55
  ): Promise<Uint8Array<ArrayBuffer>> {
74
- if (isBun()) {
75
- // @ts-ignore Only used in Bun runtime.
76
- const { deflate } = await import("node:zlib")
77
- const result = await new Promise<Uint8Array>((resolve, reject) => {
78
- deflate(data, (error: unknown, result: Uint8Array) => {
79
- if (error) reject(error)
80
- else resolve(new Uint8Array(result))
81
- })
82
- })
83
- return result as unknown as Uint8Array<ArrayBuffer>
84
- }
85
56
  return transformBytes(data, new CompressionStream("deflate"))
86
57
  }
87
58
 
@@ -1,4 +1,4 @@
1
- import { assert, describe, it } from "vitest"
1
+ import { describe, expect, it } from "bun:test"
2
2
  import { osmPbfBlobsToBlocksGenerator } from "../src/blobs-to-blocks"
3
3
  import { createOsmPbfBlobGenerator } from "../src/pbf-to-blobs"
4
4
  import {
@@ -25,32 +25,38 @@ describe("osmPbfBlobsToBlocksGenerator", () => {
25
25
  )
26
26
 
27
27
  const { value: headerBlock, done } = await generator.next()
28
- assert.isFalse(done)
28
+ expect(done).toBe(false)
29
29
  if (!isHeaderBlock(headerBlock)) {
30
- assert.fail("Expected header block")
30
+ throw new Error("Expected header block")
31
31
  }
32
- assert.deepEqual(headerBlock.bbox, header.bbox)
33
- assert.deepEqual(headerBlock.required_features, header.required_features)
34
- assert.deepEqual(headerBlock.optional_features, header.optional_features)
32
+ expect(headerBlock.bbox).toEqual(header.bbox)
33
+ expect(headerBlock.required_features).toEqual(header.required_features)
34
+ expect(headerBlock.optional_features).toEqual(header.optional_features)
35
35
 
36
36
  const { value: block, done: blockDone } = await generator.next()
37
- assert.isFalse(blockDone)
37
+ expect(blockDone).toBe(false)
38
38
  if (!isPrimitiveBlock(block)) {
39
- assert.fail("Expected primitive block")
39
+ throw new Error("Expected primitive block")
40
40
  }
41
- assert.lengthOf(block.primitivegroup, primitiveBlock.primitivegroup.length)
41
+ expect(block.primitivegroup).toHaveLength(
42
+ primitiveBlock.primitivegroup.length,
43
+ )
42
44
  const group = block.primitivegroup[0]
43
- assert.exists(primitiveBlock.primitivegroup[0])
44
- assert.exists(group?.dense)
45
- assert.exists(group?.ways?.[0])
46
- assert.lengthOf(group.ways, primitiveBlock.primitivegroup[0].ways.length)
47
- assert.deepEqual(
48
- group.ways[0].refs,
45
+ expect(primitiveBlock.primitivegroup[0]).toBeDefined()
46
+ expect(group?.dense).toBeDefined()
47
+ expect(group?.ways?.[0]).toBeDefined()
48
+ if (!group) throw new Error("group is undefined")
49
+ if (!primitiveBlock.primitivegroup[0])
50
+ throw new Error("primitiveBlock.primitivegroup[0] is undefined")
51
+ expect(group.ways).toHaveLength(
52
+ primitiveBlock.primitivegroup[0].ways.length,
53
+ )
54
+ expect(group.ways[0]?.refs).toEqual(
49
55
  primitiveBlock.primitivegroup[0]?.ways?.[0]?.refs,
50
56
  )
51
57
 
52
58
  const final = await generator.next()
53
- assert.isTrue(final.done)
59
+ expect(final.done).toBe(true)
54
60
  })
55
61
 
56
62
  it("accepts synchronous generators", async () => {
@@ -64,10 +70,10 @@ describe("osmPbfBlobsToBlocksGenerator", () => {
64
70
  )
65
71
 
66
72
  const header = await generator.next()
67
- assert.isFalse(header.done)
73
+ expect(header.done).toBe(false)
68
74
  const block = await generator.next()
69
- assert.isFalse(block.done)
75
+ expect(block.done).toBe(false)
70
76
  const final = await generator.next()
71
- assert.isTrue(final.done)
77
+ expect(final.done).toBe(true)
72
78
  })
73
79
  })