(bytes: ArrayBuffer, etag?: string)
| 487 | * Parse raw header bytes into a Header object. |
| 488 | */ |
| 489 | export function bytesToHeader(bytes: ArrayBuffer, etag?: string): Header { |
| 490 | const v = new DataView(bytes); |
| 491 | const specVersion = v.getUint8(7); |
| 492 | if (specVersion > 3) { |
| 493 | throw new Error( |
| 494 | `Archive is spec version ${specVersion} but this library supports up to spec version 3` |
| 495 | ); |
| 496 | } |
| 497 | |
| 498 | return { |
| 499 | specVersion: specVersion, |
| 500 | rootDirectoryOffset: getUint64(v, 8), |
| 501 | rootDirectoryLength: getUint64(v, 16), |
| 502 | jsonMetadataOffset: getUint64(v, 24), |
| 503 | jsonMetadataLength: getUint64(v, 32), |
| 504 | leafDirectoryOffset: getUint64(v, 40), |
| 505 | leafDirectoryLength: getUint64(v, 48), |
| 506 | tileDataOffset: getUint64(v, 56), |
| 507 | tileDataLength: getUint64(v, 64), |
| 508 | numAddressedTiles: getUint64(v, 72), |
| 509 | numTileEntries: getUint64(v, 80), |
| 510 | numTileContents: getUint64(v, 88), |
| 511 | clustered: v.getUint8(96) === 1, |
| 512 | internalCompression: v.getUint8(97), |
| 513 | tileCompression: v.getUint8(98), |
| 514 | tileType: v.getUint8(99), |
| 515 | minZoom: v.getUint8(100), |
| 516 | maxZoom: v.getUint8(101), |
| 517 | minLon: v.getInt32(102, true) / 10000000, |
| 518 | minLat: v.getInt32(106, true) / 10000000, |
| 519 | maxLon: v.getInt32(110, true) / 10000000, |
| 520 | maxLat: v.getInt32(114, true) / 10000000, |
| 521 | centerZoom: v.getUint8(118), |
| 522 | centerLon: v.getInt32(119, true) / 10000000, |
| 523 | centerLat: v.getInt32(123, true) / 10000000, |
| 524 | etag: etag, |
| 525 | }; |
| 526 | } |
| 527 | |
| 528 | function deserializeIndex(buffer: ArrayBuffer): Entry[] { |
| 529 | const p = { buf: new Uint8Array(buffer), pos: 0 }; |
no test coverage detected
searching dependent graphs…