@osmix/pbf 0.0.2 → 0.0.4

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 (105) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +75 -82
  3. package/dist/blobs-to-blocks.d.ts +52 -3
  4. package/dist/blobs-to-blocks.d.ts.map +1 -0
  5. package/dist/blobs-to-blocks.js +63 -9
  6. package/dist/blobs-to-blocks.js.map +1 -0
  7. package/dist/blocks-to-pbf.d.ts +43 -6
  8. package/dist/blocks-to-pbf.d.ts.map +1 -0
  9. package/dist/blocks-to-pbf.js +44 -7
  10. package/dist/blocks-to-pbf.js.map +1 -0
  11. package/dist/index.d.ts +29 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +29 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/pbf-to-blobs.d.ts +23 -3
  16. package/dist/pbf-to-blobs.d.ts.map +1 -0
  17. package/dist/pbf-to-blobs.js +25 -3
  18. package/dist/pbf-to-blobs.js.map +1 -0
  19. package/dist/pbf-to-blocks.d.ts +50 -7
  20. package/dist/pbf-to-blocks.d.ts.map +1 -0
  21. package/dist/pbf-to-blocks.js +51 -8
  22. package/dist/pbf-to-blocks.js.map +1 -0
  23. package/dist/proto/fileformat.d.ts +1 -0
  24. package/dist/proto/fileformat.d.ts.map +1 -0
  25. package/dist/proto/fileformat.js +1 -0
  26. package/dist/proto/fileformat.js.map +1 -0
  27. package/dist/proto/osmformat.d.ts +1 -0
  28. package/dist/proto/osmformat.d.ts.map +1 -0
  29. package/dist/proto/osmformat.js +1 -0
  30. package/dist/proto/osmformat.js.map +1 -0
  31. package/dist/spec.d.ts +1 -0
  32. package/dist/spec.d.ts.map +1 -0
  33. package/dist/spec.js +1 -0
  34. package/dist/spec.js.map +1 -0
  35. package/dist/src/blobs-to-blocks.d.ts +51 -3
  36. package/dist/src/blobs-to-blocks.d.ts.map +1 -1
  37. package/dist/src/blobs-to-blocks.js +60 -7
  38. package/dist/src/blobs-to-blocks.js.map +1 -1
  39. package/dist/src/blocks-to-pbf.d.ts +41 -5
  40. package/dist/src/blocks-to-pbf.d.ts.map +1 -1
  41. package/dist/src/blocks-to-pbf.js +41 -5
  42. package/dist/src/blocks-to-pbf.js.map +1 -1
  43. package/dist/src/index.d.ts +28 -0
  44. package/dist/src/index.d.ts.map +1 -1
  45. package/dist/src/index.js +28 -0
  46. package/dist/src/index.js.map +1 -1
  47. package/dist/src/pbf-to-blobs.d.ts +22 -3
  48. package/dist/src/pbf-to-blobs.d.ts.map +1 -1
  49. package/dist/src/pbf-to-blobs.js +24 -3
  50. package/dist/src/pbf-to-blobs.js.map +1 -1
  51. package/dist/src/pbf-to-blocks.d.ts +46 -4
  52. package/dist/src/pbf-to-blocks.d.ts.map +1 -1
  53. package/dist/src/pbf-to-blocks.js +46 -4
  54. package/dist/src/pbf-to-blocks.js.map +1 -1
  55. package/dist/src/utils.d.ts +0 -4
  56. package/dist/src/utils.d.ts.map +1 -1
  57. package/dist/src/utils.js +0 -32
  58. package/dist/src/utils.js.map +1 -1
  59. package/dist/test/blobs-to-blocks.test.js +22 -18
  60. package/dist/test/blobs-to-blocks.test.js.map +1 -1
  61. package/dist/test/pbf-to-blobs.test.js +24 -16
  62. package/dist/test/pbf-to-blobs.test.js.map +1 -1
  63. package/dist/test/read.bench.js +6 -4
  64. package/dist/test/read.bench.js.map +1 -1
  65. package/dist/test/read.test.js +5 -5
  66. package/dist/test/read.test.js.map +1 -1
  67. package/dist/test/streams.test.js +21 -13
  68. package/dist/test/streams.test.js.map +1 -1
  69. package/dist/test/utils.d.ts.map +1 -1
  70. package/dist/test/utils.js +8 -8
  71. package/dist/test/utils.js.map +1 -1
  72. package/dist/test/utils.test.js +8 -8
  73. package/dist/test/utils.test.js.map +1 -1
  74. package/dist/test/write.test.js +13 -8
  75. package/dist/test/write.test.js.map +1 -1
  76. package/dist/utils.d.ts +5 -10
  77. package/dist/utils.d.ts.map +1 -0
  78. package/dist/utils.js +8 -32
  79. package/dist/utils.js.map +1 -0
  80. package/package.json +12 -11
  81. package/src/blobs-to-blocks.ts +78 -7
  82. package/src/blocks-to-pbf.ts +42 -5
  83. package/src/index.ts +29 -0
  84. package/src/pbf-to-blobs.ts +24 -3
  85. package/src/pbf-to-blocks.ts +46 -4
  86. package/src/utils.ts +0 -29
  87. package/test/blobs-to-blocks.test.ts +25 -19
  88. package/test/pbf-to-blobs.test.ts +23 -17
  89. package/test/read.bench.ts +8 -4
  90. package/test/read.test.ts +5 -5
  91. package/test/streams.test.ts +22 -13
  92. package/test/utils.test.ts +8 -8
  93. package/test/utils.ts +8 -8
  94. package/test/write.test.ts +13 -8
  95. package/tsconfig.build.json +5 -0
  96. package/dist/test/utils.bun.test.d.ts +0 -2
  97. package/dist/test/utils.bun.test.d.ts.map +0 -1
  98. package/dist/test/utils.bun.test.js +0 -221
  99. package/dist/test/utils.bun.test.js.map +0 -1
  100. package/dist/test/verify-pbf-reading.bun.test.d.ts +0 -2
  101. package/dist/test/verify-pbf-reading.bun.test.d.ts.map +0 -1
  102. package/dist/test/verify-pbf-reading.bun.test.js +0 -32
  103. package/dist/test/verify-pbf-reading.bun.test.js.map +0 -1
  104. package/test/utils.bun.test.ts +0 -277
  105. package/test/verify-pbf-reading.bun.test.ts +0 -39
@@ -1,221 +0,0 @@
1
- import { describe, expect, test } from "vitest";
2
- import { concatUint8, isBun, toAsyncGenerator, uint32BE, webCompress, webDecompress, } from "../src/utils";
3
- describe.runIf(isBun())("utils", () => {
4
- test("wraps values into an async generator", async () => {
5
- const generator = toAsyncGenerator(3);
6
- const first = await generator.next();
7
- expect(first).toEqual({ value: 3, done: false });
8
- const done = await generator.next();
9
- expect(done).toEqual({ value: undefined, done: true });
10
- });
11
- test("consumes readable streams", async () => {
12
- const stream = new ReadableStream({
13
- start(controller) {
14
- controller.enqueue(1);
15
- controller.enqueue(2);
16
- controller.close();
17
- },
18
- });
19
- const values = [];
20
- for await (const value of toAsyncGenerator(stream))
21
- values.push(value);
22
- expect(values).toEqual([1, 2]);
23
- });
24
- test("throws on nullish inputs", async () => {
25
- const invalidInput = null;
26
- await expect(toAsyncGenerator(invalidInput).next()).rejects.toThrow("Value is null");
27
- });
28
- test("concatenates Uint8Array segments", () => {
29
- const a = Uint8Array.of(1, 2);
30
- const b = Uint8Array.of(3);
31
- expect(concatUint8(a, b)).toEqual(Uint8Array.of(1, 2, 3));
32
- });
33
- test("encodes big-endian 32-bit integers", () => {
34
- expect(uint32BE(0x01020304)).toEqual(Uint8Array.of(1, 2, 3, 4));
35
- });
36
- test("uses Bun runtime with Node.js zlib compatibility", () => {
37
- // This test verifies that Bun is available in the runtime
38
- expect(isBun()).toBe(true);
39
- });
40
- test("Node.js zlib methods work in Bun", async () => {
41
- const { deflateSync, inflateSync } = await import("node:zlib");
42
- const input = new TextEncoder().encode("test bun compression with zlib");
43
- const compressed = deflateSync(input);
44
- expect(compressed.length).toBeGreaterThan(0);
45
- expect(compressed).not.toEqual(input);
46
- const decompressed = inflateSync(compressed);
47
- expect(new Uint8Array(decompressed)).toEqual(input);
48
- });
49
- test("compress/decompress are compatible with OSM PBF zlib format", async () => {
50
- // Test that our compress/decompress functions produce zlib-compatible data
51
- // This is critical for OSM PBF compatibility
52
- const { deflateSync, inflateSync } = await import("node:zlib");
53
- const input = new TextEncoder().encode("OSM PBF uses zlib format (deflate with headers)");
54
- // Compress with our function
55
- const ourCompressed = await webCompress(input);
56
- // Decompress with Node.js zlib (what OSM PBF uses)
57
- const decompressedWithNodeZlib = inflateSync(ourCompressed);
58
- expect(new Uint8Array(decompressedWithNodeZlib)).toEqual(input);
59
- // Compress with Node.js zlib
60
- const nodeCompressed = deflateSync(input);
61
- // Decompress with our function
62
- const decompressedWithOurs = await webDecompress(new Uint8Array(nodeCompressed));
63
- expect(decompressedWithOurs).toEqual(input);
64
- });
65
- });
66
- describe.skip("CompressionStream polyfill", () => {
67
- test("compresses data using deflate format", async () => {
68
- const input = new TextEncoder().encode("test compression stream");
69
- const compressor = new CompressionStream("deflate");
70
- const writer = compressor.writable.getWriter();
71
- writer.write(input);
72
- writer.close();
73
- const chunks = [];
74
- const reader = compressor.readable.getReader();
75
- while (true) {
76
- const { done, value } = await reader.read();
77
- if (done)
78
- break;
79
- chunks.push(value);
80
- }
81
- const compressed = concatUint8(...chunks);
82
- expect(compressed.length).toBeGreaterThan(0);
83
- expect(compressed).not.toEqual(input);
84
- // Verify it's valid deflate data by decompressing
85
- const decompressed = await webDecompress(new Uint8Array(compressed));
86
- expect(decompressed).toEqual(input);
87
- });
88
- test("returns proper Uint8Array<ArrayBuffer> instances", async () => {
89
- const input = new TextEncoder().encode("type safety check");
90
- const compressor = new CompressionStream("deflate");
91
- const writer = compressor.writable.getWriter();
92
- writer.write(input);
93
- writer.close();
94
- const reader = compressor.readable.getReader();
95
- const { value } = await reader.read();
96
- expect(value).toBeDefined();
97
- if (!value)
98
- throw new Error("No value read");
99
- // Verify it's a Uint8Array
100
- expect(value).toBeInstanceOf(Uint8Array);
101
- // Verify the buffer is an ArrayBuffer (not Buffer or SharedArrayBuffer)
102
- expect(value.buffer).toBeInstanceOf(ArrayBuffer);
103
- // Verify it's not a Node.js Buffer
104
- expect(value.constructor.name).toBe("Uint8Array");
105
- });
106
- test("handles multiple writes", async () => {
107
- const compressor = new CompressionStream("deflate");
108
- const writer = compressor.writable.getWriter();
109
- // Write multiple chunks
110
- writer.write(new TextEncoder().encode("first "));
111
- writer.write(new TextEncoder().encode("second "));
112
- writer.write(new TextEncoder().encode("third"));
113
- writer.close();
114
- const chunks = [];
115
- const reader = compressor.readable.getReader();
116
- while (true) {
117
- const { done, value } = await reader.read();
118
- if (done)
119
- break;
120
- chunks.push(value);
121
- }
122
- const compressed = concatUint8(...chunks);
123
- const decompressed = await webDecompress(new Uint8Array(compressed));
124
- expect(new TextDecoder().decode(decompressed)).toBe("first second third");
125
- });
126
- });
127
- describe.skip("DecompressionStream polyfill", () => {
128
- test("decompresses deflate data", async () => {
129
- const input = new TextEncoder().encode("test decompression stream");
130
- const compressed = await webCompress(input);
131
- const decompressor = new DecompressionStream("deflate");
132
- const writer = decompressor.writable.getWriter();
133
- writer.write(compressed);
134
- writer.close();
135
- const chunks = [];
136
- const reader = decompressor.readable.getReader();
137
- while (true) {
138
- const { done, value } = await reader.read();
139
- if (done)
140
- break;
141
- chunks.push(value);
142
- }
143
- const decompressed = concatUint8(...chunks);
144
- expect(decompressed).toEqual(input);
145
- });
146
- test("returns proper Uint8Array<ArrayBuffer> instances", async () => {
147
- const input = new TextEncoder().encode("type safety check");
148
- const compressed = await webCompress(input);
149
- const decompressor = new DecompressionStream("deflate");
150
- const writer = decompressor.writable.getWriter();
151
- writer.write(compressed);
152
- writer.close();
153
- const reader = decompressor.readable.getReader();
154
- const { value } = await reader.read();
155
- expect(value).toBeDefined();
156
- if (!value)
157
- throw new Error("No value read");
158
- // Verify it's a Uint8Array
159
- expect(value).toBeInstanceOf(Uint8Array);
160
- // Verify the buffer is an ArrayBuffer (not Buffer or SharedArrayBuffer)
161
- expect(value.buffer).toBeInstanceOf(ArrayBuffer);
162
- // Verify it's not a Node.js Buffer
163
- expect(value.constructor.name).toBe("Uint8Array");
164
- });
165
- test("handles chunked compressed data", async () => {
166
- const input = new TextEncoder().encode("test chunked data");
167
- const compressed = await webCompress(input);
168
- const decompressor = new DecompressionStream("deflate");
169
- const writer = decompressor.writable.getWriter();
170
- // Write compressed data in chunks
171
- const chunkSize = 5;
172
- for (let i = 0; i < compressed.length; i += chunkSize) {
173
- const chunk = compressed.slice(i, i + chunkSize);
174
- writer.write(chunk);
175
- }
176
- writer.close();
177
- const chunks = [];
178
- const reader = decompressor.readable.getReader();
179
- while (true) {
180
- const { done, value } = await reader.read();
181
- if (done)
182
- break;
183
- chunks.push(value);
184
- }
185
- const decompressed = concatUint8(...chunks);
186
- expect(decompressed).toEqual(input);
187
- });
188
- test("round-trip compression and decompression", async () => {
189
- const input = new TextEncoder().encode("round trip test data");
190
- // Compress
191
- const compressor = new CompressionStream("deflate");
192
- const compressorWriter = compressor.writable.getWriter();
193
- compressorWriter.write(input);
194
- compressorWriter.close();
195
- const compressedChunks = [];
196
- const compressorReader = compressor.readable.getReader();
197
- while (true) {
198
- const { done, value } = await compressorReader.read();
199
- if (done)
200
- break;
201
- compressedChunks.push(value);
202
- }
203
- const compressed = concatUint8(...compressedChunks);
204
- // Decompress
205
- const decompressor = new DecompressionStream("deflate");
206
- const decompressorWriter = decompressor.writable.getWriter();
207
- decompressorWriter.write(new Uint8Array(compressed));
208
- decompressorWriter.close();
209
- const decompressedChunks = [];
210
- const decompressorReader = decompressor.readable.getReader();
211
- while (true) {
212
- const { done, value } = await decompressorReader.read();
213
- if (done)
214
- break;
215
- decompressedChunks.push(value);
216
- }
217
- const decompressed = concatUint8(...decompressedChunks);
218
- expect(decompressed).toEqual(input);
219
- });
220
- });
221
- //# sourceMappingURL=utils.bun.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.bun.test.js","sourceRoot":"","sources":["../../test/utils.bun.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EACN,WAAW,EACX,KAAK,EACL,gBAAgB,EAChB,QAAQ,EACR,WAAW,EACX,aAAa,GACb,MAAM,cAAc,CAAA;AAErB,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,GAAG,EAAE;IACrC,IAAI,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;QACvD,MAAM,SAAS,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAA;QACrC,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,CAAA;QACpC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;QAChD,MAAM,IAAI,GAAG,MAAM,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AC,IAAI,EAAE,CAAA;YACrD,IAAI,IAAI;gBAAE,MAAK;YACf,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAC7B,CAAC;QACD,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,gBAAgB,CAAC,CAAA;QAEnD,aAAa;QACb,MAAM,YAAY,GAAG,IAAI,mBAAmB,CAAC,SAAS,CAAC,CAAA;QACvD,MAAM,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAA;QAC5D,kBAAkB,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAA;QACpD,kBAAkB,CAAC,KAAK,EAAE,CAAA;QAE1B,MAAM,kBAAkB,GAAiB,EAAE,CAAA;QAC3C,MAAM,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAA;QAC5D,OAAO,IAAI,EAAE,CAAC;YACb,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,kBAAkB,CAAC,IAAI,EAAE,CAAA;YACvD,IAAI,IAAI;gBAAE,MAAK;YACf,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAC/B,CAAC;QACD,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,kBAAkB,CAAC,CAAA;QAEvD,MAAM,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=verify-pbf-reading.bun.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"verify-pbf-reading.bun.test.d.ts","sourceRoot":"","sources":["../../test/verify-pbf-reading.bun.test.ts"],"names":[],"mappings":""}
@@ -1,32 +0,0 @@
1
- import { getFixtureFile } from "@osmix/shared/test/fixtures";
2
- import { describe, expect, test } from "vitest";
3
- import { readOsmPbf } from "../src/pbf-to-blocks";
4
- import { isBun } from "../src/utils";
5
- describe.runIf(isBun())("PBF Reading with Bun", () => {
6
- test("can read an actual OSM PBF file", async () => {
7
- // Load a real PBF fixture
8
- const pbfData = await getFixtureFile("monaco.pbf");
9
- // Try to read it
10
- const result = await readOsmPbf(pbfData);
11
- // Basic sanity checks
12
- expect(result.header).toBeDefined();
13
- expect(result.header.required_features).toBeDefined();
14
- expect(result.blocks).toBeDefined();
15
- // Try to read at least one block
16
- const firstBlock = await result.blocks.next();
17
- expect(firstBlock.done).toBe(false);
18
- expect(firstBlock.value).toBeDefined();
19
- // If it's a primitive block, it should have primitivegroup
20
- if ("primitivegroup" in firstBlock.value) {
21
- expect(Array.isArray(firstBlock.value.primitivegroup)).toBe(true);
22
- }
23
- });
24
- test("header contains expected OSM data", async () => {
25
- const pbfData = await getFixtureFile("monaco.pbf");
26
- const result = await readOsmPbf(pbfData);
27
- // Check that header has the required OSM features
28
- expect(result.header.required_features).toBeDefined();
29
- expect(result.header.required_features.length).toBeGreaterThan(0);
30
- });
31
- });
32
- //# sourceMappingURL=verify-pbf-reading.bun.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"verify-pbf-reading.bun.test.js","sourceRoot":"","sources":["../../test/verify-pbf-reading.bun.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEpC,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpD,IAAI,CAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;QAClD,0BAA0B;QAC1B,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,YAAY,CAAC,CAAA;QA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
3
- concatUint8,
4
- isBun,
5
- toAsyncGenerator,
6
- uint32BE,
7
- webCompress,
8
- webDecompress,
9
- } from "../src/utils"
10
-
11
- describe.runIf(isBun())("utils", () => {
12
- test("wraps values into an async generator", async () => {
13
- const generator = toAsyncGenerator(3)
14
- const first = await generator.next()
15
- expect(first).toEqual({ value: 3, done: false })
16
- const done = await generator.next()
17
- expect(done).toEqual({ value: undefined, done: true })
18
- })
19
-
20
- test("consumes readable streams", async () => {
21
- const stream = new ReadableStream<number>({
22
- start(controller) {
23
- controller.enqueue(1)
24
- controller.enqueue(2)
25
- controller.close()
26
- },
27
- })
28
- const values: number[] = []
29
- for await (const value of toAsyncGenerator(stream)) values.push(value)
30
- expect(values).toEqual([1, 2])
31
- })
32
-
33
- test("throws on nullish inputs", async () => {
34
- const invalidInput = null as unknown as never
35
- await expect(toAsyncGenerator(invalidInput).next()).rejects.toThrow(
36
- "Value is null",
37
- )
38
- })
39
-
40
- test("concatenates Uint8Array segments", () => {
41
- const a = Uint8Array.of(1, 2)
42
- const b = Uint8Array.of(3)
43
- expect(concatUint8(a, b)).toEqual(Uint8Array.of(1, 2, 3))
44
- })
45
-
46
- test("encodes big-endian 32-bit integers", () => {
47
- expect(uint32BE(0x01020304)).toEqual(Uint8Array.of(1, 2, 3, 4))
48
- })
49
-
50
- test("uses Bun runtime with Node.js zlib compatibility", () => {
51
- // This test verifies that Bun is available in the runtime
52
- expect(isBun()).toBe(true)
53
- })
54
-
55
- test("Node.js zlib methods work in Bun", async () => {
56
- const { deflateSync, inflateSync } = await import("node:zlib")
57
- const input = new TextEncoder().encode("test bun compression with zlib")
58
- const compressed = deflateSync(input)
59
- expect(compressed.length).toBeGreaterThan(0)
60
- expect(compressed).not.toEqual(input)
61
-
62
- const decompressed = inflateSync(compressed)
63
- expect(new Uint8Array(decompressed)).toEqual(input)
64
- })
65
-
66
- test("compress/decompress are compatible with OSM PBF zlib format", async () => {
67
- // Test that our compress/decompress functions produce zlib-compatible data
68
- // This is critical for OSM PBF compatibility
69
- const { deflateSync, inflateSync } = await import("node:zlib")
70
- const input = new TextEncoder().encode(
71
- "OSM PBF uses zlib format (deflate with headers)",
72
- ) as Uint8Array<ArrayBuffer>
73
-
74
- // Compress with our function
75
- const ourCompressed = await webCompress(input)
76
-
77
- // Decompress with Node.js zlib (what OSM PBF uses)
78
- const decompressedWithNodeZlib = inflateSync(ourCompressed)
79
- expect(new Uint8Array(decompressedWithNodeZlib)).toEqual(input)
80
-
81
- // Compress with Node.js zlib
82
- const nodeCompressed = deflateSync(input)
83
-
84
- // Decompress with our function
85
- const decompressedWithOurs = await webDecompress(
86
- new Uint8Array(nodeCompressed),
87
- )
88
- expect(decompressedWithOurs).toEqual(input)
89
- })
90
- })
91
-
92
- describe.skip("CompressionStream polyfill", () => {
93
- test("compresses data using deflate format", async () => {
94
- const input = new TextEncoder().encode("test compression stream")
95
- const compressor = new CompressionStream("deflate")
96
-
97
- const writer = compressor.writable.getWriter()
98
- writer.write(input)
99
- writer.close()
100
-
101
- const chunks: Uint8Array[] = []
102
- const reader = compressor.readable.getReader()
103
- while (true) {
104
- const { done, value } = await reader.read()
105
- if (done) break
106
- chunks.push(value)
107
- }
108
-
109
- const compressed = concatUint8(...chunks)
110
- expect(compressed.length).toBeGreaterThan(0)
111
- expect(compressed).not.toEqual(input)
112
-
113
- // Verify it's valid deflate data by decompressing
114
- const decompressed = await webDecompress(new Uint8Array(compressed))
115
- expect(decompressed).toEqual(input)
116
- })
117
-
118
- test("returns proper Uint8Array<ArrayBuffer> instances", async () => {
119
- const input = new TextEncoder().encode("type safety check")
120
- const compressor = new CompressionStream("deflate")
121
-
122
- const writer = compressor.writable.getWriter()
123
- writer.write(input)
124
- writer.close()
125
-
126
- const reader = compressor.readable.getReader()
127
- const { value } = await reader.read()
128
-
129
- expect(value).toBeDefined()
130
- if (!value) throw new Error("No value read")
131
-
132
- // Verify it's a Uint8Array
133
- expect(value).toBeInstanceOf(Uint8Array)
134
- // Verify the buffer is an ArrayBuffer (not Buffer or SharedArrayBuffer)
135
- expect(value.buffer).toBeInstanceOf(ArrayBuffer)
136
- // Verify it's not a Node.js Buffer
137
- expect(value.constructor.name).toBe("Uint8Array")
138
- })
139
-
140
- test("handles multiple writes", async () => {
141
- const compressor = new CompressionStream("deflate")
142
- const writer = compressor.writable.getWriter()
143
-
144
- // Write multiple chunks
145
- writer.write(new TextEncoder().encode("first "))
146
- writer.write(new TextEncoder().encode("second "))
147
- writer.write(new TextEncoder().encode("third"))
148
- writer.close()
149
-
150
- const chunks: Uint8Array[] = []
151
- const reader = compressor.readable.getReader()
152
- while (true) {
153
- const { done, value } = await reader.read()
154
- if (done) break
155
- chunks.push(value)
156
- }
157
-
158
- const compressed = concatUint8(...chunks)
159
- const decompressed = await webDecompress(new Uint8Array(compressed))
160
- expect(new TextDecoder().decode(decompressed)).toBe("first second third")
161
- })
162
- })
163
-
164
- describe.skip("DecompressionStream polyfill", () => {
165
- test("decompresses deflate data", async () => {
166
- const input = new TextEncoder().encode(
167
- "test decompression stream",
168
- ) as Uint8Array<ArrayBuffer>
169
- const compressed = await webCompress(input)
170
-
171
- const decompressor = new DecompressionStream("deflate")
172
- const writer = decompressor.writable.getWriter()
173
- writer.write(compressed as Uint8Array<ArrayBuffer>)
174
- writer.close()
175
-
176
- const chunks: Uint8Array[] = []
177
- const reader = decompressor.readable.getReader()
178
- while (true) {
179
- const { done, value } = await reader.read()
180
- if (done) break
181
- chunks.push(value)
182
- }
183
-
184
- const decompressed = concatUint8(...chunks)
185
- expect(decompressed).toEqual(input)
186
- })
187
-
188
- test("returns proper Uint8Array<ArrayBuffer> instances", async () => {
189
- const input = new TextEncoder().encode(
190
- "type safety check",
191
- ) as Uint8Array<ArrayBuffer>
192
- const compressed = await webCompress(input)
193
-
194
- const decompressor = new DecompressionStream("deflate")
195
- const writer = decompressor.writable.getWriter()
196
- writer.write(compressed as Uint8Array<ArrayBuffer>)
197
- writer.close()
198
-
199
- const reader = decompressor.readable.getReader()
200
- const { value } = await reader.read()
201
-
202
- expect(value).toBeDefined()
203
- if (!value) throw new Error("No value read")
204
-
205
- // Verify it's a Uint8Array
206
- expect(value).toBeInstanceOf(Uint8Array)
207
- // Verify the buffer is an ArrayBuffer (not Buffer or SharedArrayBuffer)
208
- expect(value.buffer).toBeInstanceOf(ArrayBuffer)
209
- // Verify it's not a Node.js Buffer
210
- expect(value.constructor.name).toBe("Uint8Array")
211
- })
212
-
213
- test("handles chunked compressed data", async () => {
214
- const input = new TextEncoder().encode(
215
- "test chunked data",
216
- ) as Uint8Array<ArrayBuffer>
217
- const compressed = await webCompress(input)
218
-
219
- const decompressor = new DecompressionStream("deflate")
220
- const writer = decompressor.writable.getWriter()
221
-
222
- // Write compressed data in chunks
223
- const chunkSize = 5
224
- for (let i = 0; i < compressed.length; i += chunkSize) {
225
- const chunk = compressed.slice(i, i + chunkSize)
226
- writer.write(chunk)
227
- }
228
- writer.close()
229
-
230
- const chunks: Uint8Array[] = []
231
- const reader = decompressor.readable.getReader()
232
- while (true) {
233
- const { done, value } = await reader.read()
234
- if (done) break
235
- chunks.push(value)
236
- }
237
-
238
- const decompressed = concatUint8(...chunks)
239
- expect(decompressed).toEqual(input)
240
- })
241
-
242
- test("round-trip compression and decompression", async () => {
243
- const input = new TextEncoder().encode("round trip test data")
244
-
245
- // Compress
246
- const compressor = new CompressionStream("deflate")
247
- const compressorWriter = compressor.writable.getWriter()
248
- compressorWriter.write(input)
249
- compressorWriter.close()
250
-
251
- const compressedChunks: Uint8Array[] = []
252
- const compressorReader = compressor.readable.getReader()
253
- while (true) {
254
- const { done, value } = await compressorReader.read()
255
- if (done) break
256
- compressedChunks.push(value)
257
- }
258
- const compressed = concatUint8(...compressedChunks)
259
-
260
- // Decompress
261
- const decompressor = new DecompressionStream("deflate")
262
- const decompressorWriter = decompressor.writable.getWriter()
263
- decompressorWriter.write(new Uint8Array(compressed))
264
- decompressorWriter.close()
265
-
266
- const decompressedChunks: Uint8Array[] = []
267
- const decompressorReader = decompressor.readable.getReader()
268
- while (true) {
269
- const { done, value } = await decompressorReader.read()
270
- if (done) break
271
- decompressedChunks.push(value)
272
- }
273
- const decompressed = concatUint8(...decompressedChunks)
274
-
275
- expect(decompressed).toEqual(input)
276
- })
277
- })
@@ -1,39 +0,0 @@
1
- import { getFixtureFile } from "@osmix/shared/test/fixtures"
2
- import { describe, expect, test } from "vitest"
3
- import { readOsmPbf } from "../src/pbf-to-blocks"
4
- import { isBun } from "../src/utils"
5
-
6
- describe.runIf(isBun())("PBF Reading with Bun", () => {
7
- test("can read an actual OSM PBF file", async () => {
8
- // Load a real PBF fixture
9
- const pbfData = await getFixtureFile("monaco.pbf")
10
-
11
- // Try to read it
12
- const result = await readOsmPbf(pbfData)
13
-
14
- // Basic sanity checks
15
- expect(result.header).toBeDefined()
16
- expect(result.header.required_features).toBeDefined()
17
- expect(result.blocks).toBeDefined()
18
-
19
- // Try to read at least one block
20
- const firstBlock = await result.blocks.next()
21
- expect(firstBlock.done).toBe(false)
22
- expect(firstBlock.value).toBeDefined()
23
-
24
- // If it's a primitive block, it should have primitivegroup
25
- if ("primitivegroup" in firstBlock.value) {
26
- expect(Array.isArray(firstBlock.value.primitivegroup)).toBe(true)
27
- }
28
- })
29
-
30
- test("header contains expected OSM data", async () => {
31
- const pbfData = await getFixtureFile("monaco.pbf")
32
-
33
- const result = await readOsmPbf(pbfData)
34
-
35
- // Check that header has the required OSM features
36
- expect(result.header.required_features).toBeDefined()
37
- expect(result.header.required_features.length).toBeGreaterThan(0)
38
- })
39
- })