mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 10:51:07 +00:00
Replace compression polyfill ("Worker" related errors) (#222)
* replace compression-streams-polyfill with globalThis check [#167] * work around web worker issue with decompression polyfill. * js 2.10.0-beta.0 * js 2.10.0; update examples
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
2.10.0
|
||||
|
||||
* Replace `DecompressionStream` polyfill with own `globalThis` detection because of web workers problems.
|
||||
|
||||
2.9.0
|
||||
|
||||
* Recognize AVIF TileType
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="utf-8"/>
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
|
||||
<script src="https://unpkg.com/leaflet@1.9.0/dist/leaflet.js"></script>
|
||||
<script src="https://unpkg.com/pmtiles@2.9.0/dist/index.js"></script>
|
||||
<script src="https://unpkg.com/pmtiles@2.10.0/dist/index.js"></script>
|
||||
<style>
|
||||
body, #map {
|
||||
height:100vh;
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
<meta charset="utf-8"/>
|
||||
<link rel="stylesheet" href="https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.css" crossorigin="anonymous">
|
||||
<script src="https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.js" crossorigin="anonymous"></script>
|
||||
<script src="https://unpkg.com/pmtiles@2.9.0/dist/index.js"></script>
|
||||
<!-- <script src="https://unpkg.com/pmtiles@2.10.0/dist/index.js"></script> -->
|
||||
<script src="../dist/index.js"></script>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
@@ -78,4 +79,4 @@
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="utf-8"/>
|
||||
<link rel="stylesheet" href="https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.css" crossorigin="anonymous">
|
||||
<script src="https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.js" crossorigin="anonymous"></script>
|
||||
<script src="https://unpkg.com/pmtiles@2.9.0/dist/index.js"></script>
|
||||
<script src="https://unpkg.com/pmtiles@2.10.0/dist/index.js"></script>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
@@ -65,4 +65,4 @@
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
15
js/index.ts
15
js/index.ts
@@ -1,4 +1,4 @@
|
||||
import { makeDecompressionStream } from "compression-streams-polyfill/ponyfill";
|
||||
import { decompressSync } from "fflate";
|
||||
import v2 from "./v2";
|
||||
export * from "./adapters";
|
||||
|
||||
@@ -162,10 +162,15 @@ async function defaultDecompress(
|
||||
if (compression === Compression.None || compression === Compression.Unknown) {
|
||||
return buf;
|
||||
} else if (compression === Compression.Gzip) {
|
||||
let stream = new Response(buf).body!;
|
||||
const decompressionStream = makeDecompressionStream(TransformStream);
|
||||
let result = stream.pipeThrough(new decompressionStream("gzip"));
|
||||
return new Response(result).arrayBuffer();
|
||||
if (typeof (globalThis as any).DecompressionStream == "undefined") {
|
||||
return decompressSync(new Uint8Array(buf));
|
||||
} else {
|
||||
let stream = new Response(buf).body!;
|
||||
let result: ReadableStream<Uint8Array> = stream.pipeThrough(
|
||||
new (globalThis as any).DecompressionStream("gzip")
|
||||
);
|
||||
return new Response(result).arrayBuffer();
|
||||
}
|
||||
} else {
|
||||
throw Error("Compression method not supported");
|
||||
}
|
||||
|
||||
33
js/package-lock.json
generated
33
js/package-lock.json
generated
@@ -1,15 +1,14 @@
|
||||
{
|
||||
"name": "pmtiles",
|
||||
"version": "2.9.0",
|
||||
"version": "2.10.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "pmtiles",
|
||||
"version": "2.9.0",
|
||||
"version": "2.10.0",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"compression-streams-polyfill": "^0.1.3",
|
||||
"fflate": "^0.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -64,19 +63,6 @@
|
||||
"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",
|
||||
@@ -536,21 +522,6 @@
|
||||
"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",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pmtiles",
|
||||
"version": "2.9.0",
|
||||
"version": "2.10.0",
|
||||
"description": "PMTiles archive decoder for browsers",
|
||||
"main": "dist/index.cjs",
|
||||
"module": "dist/index.mjs",
|
||||
@@ -32,7 +32,6 @@
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"compression-streams-polyfill": "^0.1.3",
|
||||
"fflate": "^0.8.0"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user