mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 10:51:07 +00:00
js client: show error when future spec version is read
This commit is contained in:
@@ -309,8 +309,15 @@ export class FetchSource implements Source {
|
|||||||
|
|
||||||
export function bytesToHeader(bytes: ArrayBuffer, etag?: string): Header {
|
export function bytesToHeader(bytes: ArrayBuffer, etag?: string): Header {
|
||||||
const v = new DataView(bytes);
|
const v = new DataView(bytes);
|
||||||
|
const spec_version = v.getUint8(7);
|
||||||
|
if (spec_version > 3) {
|
||||||
|
throw Error(
|
||||||
|
`Archive is spec version ${spec_version} but this library supports up to spec version 3`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
specVersion: 3,
|
specVersion: spec_version,
|
||||||
rootDirectoryOffset: Number(v.getBigUint64(8, true)),
|
rootDirectoryOffset: Number(v.getBigUint64(8, true)),
|
||||||
rootDirectoryLength: Number(v.getBigUint64(16, true)),
|
rootDirectoryLength: Number(v.getBigUint64(16, true)),
|
||||||
jsonMetadataOffset: Number(v.getBigUint64(24, true)),
|
jsonMetadataOffset: Number(v.getBigUint64(24, true)),
|
||||||
|
|||||||
BIN
js/test/data/invalid_v4.pmtiles
Normal file
BIN
js/test/data/invalid_v4.pmtiles
Normal file
Binary file not shown.
@@ -192,7 +192,17 @@ test("cache check magic number", async (assertion) => {
|
|||||||
await cache.getHeader(source);
|
await cache.getHeader(source);
|
||||||
assertion.fail("Should have thrown");
|
assertion.fail("Should have thrown");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
assertion.ok(e instanceof Error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("cache check future spec version", async (assertion) => {
|
||||||
|
const source = new TestNodeFileSource("test/data/invalid_v4.pmtiles", "1");
|
||||||
|
const cache = new SharedPromiseCache();
|
||||||
|
try {
|
||||||
|
await cache.getHeader(source);
|
||||||
|
assertion.fail("Should have thrown");
|
||||||
|
} catch (e) {
|
||||||
assertion.ok(e instanceof Error);
|
assertion.ok(e instanceof Error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user