Skip to content

Commit

Permalink
Merge pull request #9861 from CesiumGS/zip-pako
Browse files Browse the repository at this point in the history
Configure zip.js with pako workers
  • Loading branch information
lilleyse authored Oct 11, 2021
2 parents 810de0b + 15f39ae commit 7067c04
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ Source/ThirdParty/Tween.js
Source/ThirdParty/Uri.js
Source/ThirdParty/when.js
Source/ThirdParty/zip.js
Source/ThirdParty/Workers/pako_inflate.min.js
Source/ThirdParty/Workers/pako_deflate.min.js
Source/ThirdParty/Workers/z-worker-pako.js

/node_modules
npm-debug.log
Expand Down
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

### 1.86.1 - 2021-10-15

##### Fixes :wrench:

- Fixed zip.js configurations causing CesiumJS to not work with Node 16. [#9861](https://github.com/CesiumGS/cesium/pull/9861)

### 1.86 - 2021-10-01

##### Breaking Changes :mega:
Expand Down
8 changes: 8 additions & 0 deletions Source/DataSources/KmlDataSource.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ArcType from "../Core/ArcType.js";
import AssociativeArray from "../Core/AssociativeArray.js";
import BoundingRectangle from "../Core/BoundingRectangle.js";
import buildModuleUrl from "../Core/buildModuleUrl.js";
import Cartesian2 from "../Core/Cartesian2.js";
import Cartesian3 from "../Core/Cartesian3.js";
import Cartographic from "../Core/Cartographic.js";
Expand Down Expand Up @@ -3165,6 +3166,13 @@ function loadKml(
}

function loadKmz(dataSource, entityCollection, blob, sourceResource) {
var zWorkerUrl = buildModuleUrl("ThirdParty/Workers/z-worker-pako.js");
zip.configure({
workerScripts: {
deflate: [zWorkerUrl, "./pako_deflate.min.js"],
inflate: [zWorkerUrl, "./pako_inflate.min.js"],
},
});
var reader = new zip.ZipReader(new zip.BlobReader(blob));
return when(reader.getEntries()).then(function (entries) {
var promises = [];
Expand Down
8 changes: 8 additions & 0 deletions Source/DataSources/exportKml.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import buildModuleUrl from "../Core/buildModuleUrl.js";
import Cartesian2 from "../Core/Cartesian2.js";
import Cartesian3 from "../Core/Cartesian3.js";
import Cartographic from "../Core/Cartographic.js";
Expand Down Expand Up @@ -323,6 +324,13 @@ function exportKml(options) {
}

function createKmz(kmlString, externalFiles) {
var zWorkerUrl = buildModuleUrl("ThirdParty/Workers/z-worker-pako.js");
zip.configure({
workerScripts: {
deflate: [zWorkerUrl, "./pako_deflate.min.js"],
inflate: [zWorkerUrl, "./pako_inflate.min.js"],
},
});
var blobWriter = new zip.BlobWriter();
var writer = new zip.ZipWriter(blobWriter);
// We need to only write one file at a time so the zip doesn't get corrupted
Expand Down
2 changes: 1 addition & 1 deletion ThirdParty/npm/zip.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import * as zip from "@zip.js/zip.js/lib/zip.js";
import * as zip from "@zip.js/zip.js/lib/zip-no-worker.js";
export { zip as default };
17 changes: 15 additions & 2 deletions gulpfile.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ function combineRelease() {

gulp.task("combineRelease", gulp.series("build", combineRelease));

// Copy Draco3D files from node_modules into Source
gulp.task("prepare", function (done) {
// Copy Draco3D files from node_modules into Source
fs.copyFileSync(
"node_modules/draco3d/draco_decoder_nodejs.js",
"Source/ThirdParty/Workers/draco_decoder_nodejs.js"
Expand All @@ -391,6 +391,19 @@ gulp.task("prepare", function (done) {
"node_modules/draco3d/draco_decoder.wasm",
"Source/ThirdParty/draco_decoder.wasm"
);
// Copy pako and zip.js worker files to Source/ThirdParty
fs.copyFileSync(
"node_modules/pako/dist/pako_inflate.min.js",
"Source/ThirdParty/Workers/pako_inflate.min.js"
);
fs.copyFileSync(
"node_modules/pako/dist/pako_deflate.min.js",
"Source/ThirdParty/Workers/pako_deflate.min.js"
);
fs.copyFileSync(
"node_modules/@zip.js/zip.js/dist/z-worker-pako.js",
"Source/ThirdParty/Workers/z-worker-pako.js"
);
done();
});

Expand Down Expand Up @@ -434,7 +447,7 @@ gulp.task(
//See https://github.com/CesiumGS/cesium/pull/3106#discussion_r42793558 for discussion.
glslToJavaScript(false, "Build/minifyShaders.state");

// Remove prepare step from package.json to avoid redownloading Draco3d files
// Remove prepare step from package.json to avoid running "prepare" an extra time.
delete packageJson.scripts.prepare;
fs.writeFileSync(
"./Build/package.noprepare.json",
Expand Down

0 comments on commit 7067c04

Please sign in to comment.