Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure zip.js with pako workers #9861

Merged
merged 14 commits into from
Oct 11, 2021
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