mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 02:41:09 +00:00
This commit is contained in:
15
js/index.ts
15
js/index.ts
@@ -1,4 +1,4 @@
|
||||
import { decompressSync } from "fflate";
|
||||
import { makeDecompressionStream } from "compression-streams-polyfill/ponyfill";
|
||||
import v2 from "./v2";
|
||||
export * from "./adapters";
|
||||
|
||||
@@ -155,14 +155,17 @@ type DecompressFunc = (
|
||||
compression: Compression
|
||||
) => Promise<ArrayBuffer>;
|
||||
|
||||
async function fflateDecompress(
|
||||
async function defaultDecompress(
|
||||
buf: ArrayBuffer,
|
||||
compression: Compression
|
||||
): Promise<ArrayBuffer> {
|
||||
if (compression === Compression.None || compression === Compression.Unknown) {
|
||||
return buf;
|
||||
} else if (compression === Compression.Gzip) {
|
||||
return decompressSync(new Uint8Array(buf));
|
||||
let stream = new Response(buf).body!;
|
||||
const decompressionStream = makeDecompressionStream(TransformStream);
|
||||
let result = stream.pipeThrough(new decompressionStream("gzip"));
|
||||
return new Response(result).arrayBuffer();
|
||||
} else {
|
||||
throw Error("Compression method not supported");
|
||||
}
|
||||
@@ -547,7 +550,7 @@ export class ResolvedValueCache {
|
||||
constructor(
|
||||
maxCacheEntries = 100,
|
||||
prefetch = true,
|
||||
decompress: DecompressFunc = fflateDecompress
|
||||
decompress: DecompressFunc = defaultDecompress
|
||||
) {
|
||||
this.cache = new Map<string, ResolvedValue>();
|
||||
this.maxCacheEntries = maxCacheEntries;
|
||||
@@ -682,7 +685,7 @@ export class SharedPromiseCache {
|
||||
constructor(
|
||||
maxCacheEntries = 100,
|
||||
prefetch = true,
|
||||
decompress: DecompressFunc = fflateDecompress
|
||||
decompress: DecompressFunc = defaultDecompress
|
||||
) {
|
||||
this.cache = new Map<string, SharedPromiseCacheValue>();
|
||||
this.maxCacheEntries = maxCacheEntries;
|
||||
@@ -824,7 +827,7 @@ export class PMTiles {
|
||||
if (decompress) {
|
||||
this.decompress = decompress;
|
||||
} else {
|
||||
this.decompress = fflateDecompress;
|
||||
this.decompress = defaultDecompress;
|
||||
}
|
||||
if (cache) {
|
||||
this.cache = cache;
|
||||
|
||||
43
js/package-lock.json
generated
43
js/package-lock.json
generated
@@ -9,7 +9,8 @@
|
||||
"version": "2.7.2",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"fflate": "^0.7.3"
|
||||
"compression-streams-polyfill": "^0.1.3",
|
||||
"fflate": "^0.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.11.9",
|
||||
@@ -63,6 +64,19 @@
|
||||
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/compression-streams-polyfill": {
|
||||
"version": "0.1.3",
|
||||
"resolved": "https://registry.npmjs.org/compression-streams-polyfill/-/compression-streams-polyfill-0.1.3.tgz",
|
||||
"integrity": "sha512-FOvusJGoWTKRb9JNMtCc42C81SdyJhJws/lbExADOkH1R8KpdzY4yFO6953lW5Vw498pnGXoyosr807KTr8BAA==",
|
||||
"dependencies": {
|
||||
"fflate": "^0.7.4"
|
||||
}
|
||||
},
|
||||
"node_modules/compression-streams-polyfill/node_modules/fflate": {
|
||||
"version": "0.7.4",
|
||||
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.7.4.tgz",
|
||||
"integrity": "sha512-5u2V/CDW15QM1XbbgS+0DfPxVB+jUKhWEKuuFuHncbk3tEEqzmoXL+2KyOFuKGqOnmdIy0/davWF1CkuwtibCw=="
|
||||
},
|
||||
"node_modules/esbuild": {
|
||||
"version": "0.15.15",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.15.15.tgz",
|
||||
@@ -437,9 +451,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/fflate": {
|
||||
"version": "0.7.3",
|
||||
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.7.3.tgz",
|
||||
"integrity": "sha512-0Zz1jOzJWERhyhsimS54VTqOteCNwRtIlh8isdL0AXLo0g7xNTfTL7oWrkmCnPhZGocKIkWHBistBrrpoNH3aw=="
|
||||
"version": "0.8.0",
|
||||
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.0.tgz",
|
||||
"integrity": "sha512-FAdS4qMuFjsJj6XHbBaZeXOgaypXp8iw/Tpyuq/w3XA41jjLHT8NPA+n7czH/DDhdncq0nAyDZmPeWXh2qmdIg=="
|
||||
},
|
||||
"node_modules/prettier": {
|
||||
"version": "2.8.4",
|
||||
@@ -522,6 +536,21 @@
|
||||
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
|
||||
"dev": true
|
||||
},
|
||||
"compression-streams-polyfill": {
|
||||
"version": "0.1.3",
|
||||
"resolved": "https://registry.npmjs.org/compression-streams-polyfill/-/compression-streams-polyfill-0.1.3.tgz",
|
||||
"integrity": "sha512-FOvusJGoWTKRb9JNMtCc42C81SdyJhJws/lbExADOkH1R8KpdzY4yFO6953lW5Vw498pnGXoyosr807KTr8BAA==",
|
||||
"requires": {
|
||||
"fflate": "^0.7.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"fflate": {
|
||||
"version": "0.7.4",
|
||||
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.7.4.tgz",
|
||||
"integrity": "sha512-5u2V/CDW15QM1XbbgS+0DfPxVB+jUKhWEKuuFuHncbk3tEEqzmoXL+2KyOFuKGqOnmdIy0/davWF1CkuwtibCw=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"esbuild": {
|
||||
"version": "0.15.15",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.15.15.tgz",
|
||||
@@ -703,9 +732,9 @@
|
||||
"optional": true
|
||||
},
|
||||
"fflate": {
|
||||
"version": "0.7.3",
|
||||
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.7.3.tgz",
|
||||
"integrity": "sha512-0Zz1jOzJWERhyhsimS54VTqOteCNwRtIlh8isdL0AXLo0g7xNTfTL7oWrkmCnPhZGocKIkWHBistBrrpoNH3aw=="
|
||||
"version": "0.8.0",
|
||||
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.0.tgz",
|
||||
"integrity": "sha512-FAdS4qMuFjsJj6XHbBaZeXOgaypXp8iw/Tpyuq/w3XA41jjLHT8NPA+n7czH/DDhdncq0nAyDZmPeWXh2qmdIg=="
|
||||
},
|
||||
"prettier": {
|
||||
"version": "2.8.4",
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"fflate": "^0.7.3"
|
||||
"compression-streams-polyfill": "^0.1.3",
|
||||
"fflate": "^0.8.0"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user