@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.
- package/CHANGELOG.md +6 -0
- package/README.md +75 -82
- package/dist/src/blobs-to-blocks.d.ts +51 -3
- package/dist/src/blobs-to-blocks.d.ts.map +1 -1
- package/dist/src/blobs-to-blocks.js +60 -7
- package/dist/src/blobs-to-blocks.js.map +1 -1
- package/dist/src/blocks-to-pbf.d.ts +41 -5
- package/dist/src/blocks-to-pbf.d.ts.map +1 -1
- package/dist/src/blocks-to-pbf.js +41 -5
- package/dist/src/blocks-to-pbf.js.map +1 -1
- package/dist/src/index.d.ts +28 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +28 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/pbf-to-blobs.d.ts +22 -3
- package/dist/src/pbf-to-blobs.d.ts.map +1 -1
- package/dist/src/pbf-to-blobs.js +24 -3
- package/dist/src/pbf-to-blobs.js.map +1 -1
- package/dist/src/pbf-to-blocks.d.ts +46 -4
- package/dist/src/pbf-to-blocks.d.ts.map +1 -1
- package/dist/src/pbf-to-blocks.js +46 -4
- package/dist/src/pbf-to-blocks.js.map +1 -1
- package/dist/src/utils.d.ts +0 -4
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +0 -32
- package/dist/src/utils.js.map +1 -1
- package/dist/test/blobs-to-blocks.test.js +22 -18
- package/dist/test/blobs-to-blocks.test.js.map +1 -1
- package/dist/test/pbf-to-blobs.test.js +24 -16
- package/dist/test/pbf-to-blobs.test.js.map +1 -1
- package/dist/test/read.bench.js +6 -4
- package/dist/test/read.bench.js.map +1 -1
- package/dist/test/read.test.js +5 -5
- package/dist/test/read.test.js.map +1 -1
- package/dist/test/streams.test.js +21 -13
- package/dist/test/streams.test.js.map +1 -1
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +8 -8
- package/dist/test/utils.js.map +1 -1
- package/dist/test/utils.test.js +8 -8
- package/dist/test/utils.test.js.map +1 -1
- package/dist/test/write.test.js +13 -8
- package/dist/test/write.test.js.map +1 -1
- package/package.json +6 -7
- package/src/blobs-to-blocks.ts +78 -7
- package/src/blocks-to-pbf.ts +42 -5
- package/src/index.ts +29 -0
- package/src/pbf-to-blobs.ts +24 -3
- package/src/pbf-to-blocks.ts +46 -4
- package/src/utils.ts +0 -29
- package/test/blobs-to-blocks.test.ts +25 -19
- package/test/pbf-to-blobs.test.ts +23 -17
- package/test/read.bench.ts +8 -4
- package/test/read.test.ts +5 -5
- package/test/streams.test.ts +22 -13
- package/test/utils.test.ts +8 -8
- package/test/utils.ts +8 -8
- package/test/write.test.ts +13 -8
- package/dist/blobs-to-blocks.d.ts +0 -5
- package/dist/blobs-to-blocks.js +0 -21
- package/dist/blocks-to-pbf.d.ts +0 -16
- package/dist/blocks-to-pbf.js +0 -73
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -8
- package/dist/pbf-to-blobs.d.ts +0 -6
- package/dist/pbf-to-blobs.js +0 -48
- package/dist/pbf-to-blocks.d.ts +0 -20
- package/dist/pbf-to-blocks.js +0 -53
- package/dist/proto/fileformat.d.ts +0 -26
- package/dist/proto/fileformat.js +0 -56
- package/dist/proto/osmformat.d.ts +0 -91
- package/dist/proto/osmformat.js +0 -458
- package/dist/spec.d.ts +0 -5
- package/dist/spec.js +0 -9
- package/dist/test/utils.bun.test.d.ts +0 -2
- package/dist/test/utils.bun.test.d.ts.map +0 -1
- package/dist/test/utils.bun.test.js +0 -221
- package/dist/test/utils.bun.test.js.map +0 -1
- package/dist/test/verify-pbf-reading.bun.test.d.ts +0 -2
- package/dist/test/verify-pbf-reading.bun.test.d.ts.map +0 -1
- package/dist/test/verify-pbf-reading.bun.test.js +0 -32
- package/dist/test/verify-pbf-reading.bun.test.js.map +0 -1
- package/dist/utils.d.ts +0 -27
- package/dist/utils.js +0 -92
- package/test/utils.bun.test.ts +0 -277
- 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,SAAS,CAAC,IAAI,EAAE,CAAA;QACnC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;IACvD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,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 +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,IA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,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
package/dist/utils.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export type AsyncGeneratorValue<T> = T | ReadableStream<T> | AsyncGenerator<T> | Promise<T> | Promise<ReadableStream<T>> | Promise<AsyncGenerator<T>>;
|
|
2
|
-
/**
|
|
3
|
-
* Normalizes values, streams, and iterables into a unified async generator interface.
|
|
4
|
-
*/
|
|
5
|
-
export declare function toAsyncGenerator<T>(v: AsyncGeneratorValue<T>): AsyncGenerator<T>;
|
|
6
|
-
/**
|
|
7
|
-
* Returns true when executing inside the Bun runtime.
|
|
8
|
-
*/
|
|
9
|
-
export declare function isBun(): boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Decompresses binary data using runtime-native APIs.
|
|
12
|
-
* Falls back to Node zlib when running under Bun to match OSM PBF expectations.
|
|
13
|
-
*/
|
|
14
|
-
export declare function decompress(data: Uint8Array): Promise<Uint8Array>;
|
|
15
|
-
/**
|
|
16
|
-
* Compresses binary data using runtime-native APIs.
|
|
17
|
-
* Falls back to Node zlib when running under Bun to match OSM PBF expectations.
|
|
18
|
-
*/
|
|
19
|
-
export declare function compress(data: Uint8Array): Promise<Uint8Array>;
|
|
20
|
-
/**
|
|
21
|
-
* Concatenates multiple `Uint8Array` segments into a contiguous array.
|
|
22
|
-
*/
|
|
23
|
-
export declare function concatUint8(...parts: Uint8Array[]): Uint8Array;
|
|
24
|
-
/**
|
|
25
|
-
* Encodes a 32-bit big-endian unsigned integer as a four-byte buffer.
|
|
26
|
-
*/
|
|
27
|
-
export declare function uint32BE(n: number): Uint8Array;
|
package/dist/utils.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { streamToBytes } from "@osmix/shared/stream-to-bytes";
|
|
2
|
-
/**
|
|
3
|
-
* Normalizes values, streams, and iterables into a unified async generator interface.
|
|
4
|
-
*/
|
|
5
|
-
export async function* toAsyncGenerator(v) {
|
|
6
|
-
if (v instanceof Promise)
|
|
7
|
-
return toAsyncGenerator(await v);
|
|
8
|
-
if (v == null)
|
|
9
|
-
throw Error("Value is null");
|
|
10
|
-
if (v instanceof ReadableStream) {
|
|
11
|
-
const reader = v.getReader();
|
|
12
|
-
while (true) {
|
|
13
|
-
const { done, value } = await reader.read();
|
|
14
|
-
if (done)
|
|
15
|
-
break;
|
|
16
|
-
yield value;
|
|
17
|
-
}
|
|
18
|
-
reader.releaseLock();
|
|
19
|
-
}
|
|
20
|
-
else if (ArrayBuffer.isView(v) || v instanceof ArrayBuffer) {
|
|
21
|
-
// Treat ArrayBuffer and TypedArrays (like Uint8Array, Buffer) as single values
|
|
22
|
-
yield v;
|
|
23
|
-
}
|
|
24
|
-
else if (typeof v === "object" &&
|
|
25
|
-
(Symbol.asyncIterator in v || Symbol.iterator in v)) {
|
|
26
|
-
return v;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
yield v;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Returns true when executing inside the Bun runtime.
|
|
34
|
-
*/
|
|
35
|
-
export function isBun() {
|
|
36
|
-
return "Bun" in globalThis;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Decompresses binary data using runtime-native APIs.
|
|
40
|
-
* Falls back to Node zlib when running under Bun to match OSM PBF expectations.
|
|
41
|
-
*/
|
|
42
|
-
export async function decompress(data) {
|
|
43
|
-
// Check if we're in Bun runtime - use Node.js zlib for proper OSM PBF zlib format support
|
|
44
|
-
if (isBun()) {
|
|
45
|
-
const { inflateSync } = await import("node:zlib");
|
|
46
|
-
return new Uint8Array(inflateSync(data));
|
|
47
|
-
}
|
|
48
|
-
// Fallback to standard Web API
|
|
49
|
-
const decompressedStream = new Blob([data])
|
|
50
|
-
.stream()
|
|
51
|
-
.pipeThrough(new DecompressionStream("deflate"));
|
|
52
|
-
return streamToBytes(decompressedStream);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Compresses binary data using runtime-native APIs.
|
|
56
|
-
* Falls back to Node zlib when running under Bun to match OSM PBF expectations.
|
|
57
|
-
*/
|
|
58
|
-
export async function compress(data) {
|
|
59
|
-
// Check if we're in Bun runtime - use Node.js zlib for proper OSM PBF zlib format support
|
|
60
|
-
if (isBun()) {
|
|
61
|
-
const { deflateSync } = await import("node:zlib");
|
|
62
|
-
return new Uint8Array(deflateSync(data));
|
|
63
|
-
}
|
|
64
|
-
// Fallback to standard Web API
|
|
65
|
-
const stream = new CompressionStream("deflate");
|
|
66
|
-
const compressedStream = new Blob([data]).stream().pipeThrough(stream);
|
|
67
|
-
return streamToBytes(compressedStream);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Concatenates multiple `Uint8Array` segments into a contiguous array.
|
|
71
|
-
*/
|
|
72
|
-
export function concatUint8(...parts) {
|
|
73
|
-
const total = parts.reduce((n, p) => n + p.length, 0);
|
|
74
|
-
const out = new Uint8Array(total);
|
|
75
|
-
let offset = 0;
|
|
76
|
-
for (const p of parts) {
|
|
77
|
-
out.set(p, offset);
|
|
78
|
-
offset += p.length;
|
|
79
|
-
}
|
|
80
|
-
return out;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Encodes a 32-bit big-endian unsigned integer as a four-byte buffer.
|
|
84
|
-
*/
|
|
85
|
-
export function uint32BE(n) {
|
|
86
|
-
const out = new Uint8Array(4);
|
|
87
|
-
out[0] = (n >>> 24) & 0xff;
|
|
88
|
-
out[1] = (n >>> 16) & 0xff;
|
|
89
|
-
out[2] = (n >>> 8) & 0xff;
|
|
90
|
-
out[3] = n & 0xff;
|
|
91
|
-
return out;
|
|
92
|
-
}
|