Skip to content

Commit

Permalink
Replace compression polyfill ("Worker" related errors) (#222)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bdon authored Jul 31, 2023
1 parent 6a4a403 commit 77c956d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 43 deletions.
4 changes: 4 additions & 0 deletions js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion js/examples/leaflet.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8"/>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/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;
Expand Down
5 changes: 3 additions & 2 deletions js/examples/maplibre.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<meta charset="utf-8"/>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/maplibre-gl.css" crossorigin="anonymous">
<script src="https://unpkg.com/[email protected]/dist/maplibre-gl.js" crossorigin="anonymous"></script>
<script src="https://unpkg.com/[email protected]/dist/index.js"></script>
<!-- <script src="https://unpkg.com/[email protected]/dist/index.js"></script> -->
<script src="../dist/index.js"></script>
<style>
body {
margin: 0;
Expand Down Expand Up @@ -78,4 +79,4 @@
})
</script>
</body>
</html>
</html>
4 changes: 2 additions & 2 deletions js/examples/maplibre_raster_dem.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8"/>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/maplibre-gl.css" crossorigin="anonymous">
<script src="https://unpkg.com/[email protected]/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;
Expand Down Expand Up @@ -65,4 +65,4 @@
})
</script>
</body>
</html>
</html>
15 changes: 10 additions & 5 deletions js/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { makeDecompressionStream } from "compression-streams-polyfill/ponyfill";
import { decompressSync } from "fflate";
import v2 from "./v2";
export * from "./adapters";

Expand Down Expand Up @@ -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");
}
Expand Down
33 changes: 2 additions & 31 deletions js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -32,7 +32,6 @@
"typescript": "^4.5.5"
},
"dependencies": {
"compression-streams-polyfill": "^0.1.3",
"fflate": "^0.8.0"
}
}

0 comments on commit 77c956d

Please sign in to comment.