replace zip.js with JSzip

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
TRIGUBF
2023-08-23 17:06:22 +02:00
committed by Fredrik Adelöw
parent 400beacb70
commit 149c6f03ca
3 changed files with 45 additions and 29 deletions
+1 -1
View File
@@ -73,7 +73,6 @@
"@rjsf/validator-ajv8": "5.7.3",
"@types/react": "^16.13.1 || ^17.0.0",
"@uiw/react-codemirror": "^4.9.3",
"@zip.js/zip.js": "^2.7.24",
"classnames": "^2.2.6",
"event-source-polyfill": "^1.0.31",
"git-url-parse": "^13.0.0",
@@ -81,6 +80,7 @@
"immer": "^9.0.1",
"json-schema": "^0.4.0",
"json-schema-library": "^7.3.9",
"jszip": "^3.10.1",
"lodash": "^4.17.21",
"luxon": "^3.0.0",
"qs": "^6.9.4",
@@ -26,7 +26,7 @@ import React, {
useRef,
useState,
} from 'react';
import * as zip from "@zip.js/zip.js";
import JSZip from 'jszip';
import {
scaffolderApiRef,
ScaffolderDryRunResponse,
@@ -198,33 +198,28 @@ export function useDryRun(): DryRun {
}
async function createZipDownload(directoryContents: { path: string; base64Content: string; executable: boolean; }[], name: string) {
// needs zip.js
// Creates a BlobWriter object where the zip content will be written.
const zipFileWriter = new zip.BlobWriter();
// Creates a ZipWriter object writing data via `zipFileWriter`, adds the entry
const zipWriter = new zip.ZipWriter(zipFileWriter);
const zip = new JSZip();
for (const d of directoryContents) {
// Decode text content from base64 to ascii
const converted = atob(d.base64Content);
// Creates a TextReader object storing the text of the entry to add in the zip (i.e. "Hello world!").
const fileReader = new zip.TextReader(converted);
await zipWriter.add(d.path, fileReader);
// add folder/file to zip
await zip.file(d.path, converted);
}
// Closes the writer.
await zipWriter.close();
zip.generateAsync({type:"blob"}).then((blob) => {
saveAs(blob, name);
}, (err) => {
throw new Error(err);
});
}
// Retrieves the Blob object containing the zip content into `zipFileBlob`
const zipFileBlob = await zipFileWriter.getData();
// Download zip
// Download zip
function saveAs(blob: Blob, name: string) {
const a = document.createElement('a');
a.href = URL.createObjectURL(zipFileBlob);
a.href = URL.createObjectURL(blob);
a.download = `dry-run-${name}.zip`;
a.click();
URL.revokeObjectURL(a.href);
+31 -10
View File
@@ -8796,7 +8796,6 @@ __metadata:
"@types/json-schema": ^7.0.9
"@types/react": ^16.13.1 || ^17.0.0
"@uiw/react-codemirror": ^4.9.3
"@zip.js/zip.js": ^2.7.24
classnames: ^2.2.6
event-source-polyfill: ^1.0.31
git-url-parse: ^13.0.0
@@ -8804,6 +8803,7 @@ __metadata:
immer: ^9.0.1
json-schema: ^0.4.0
json-schema-library: ^7.3.9
jszip: ^3.10.1
lodash: ^4.17.21
luxon: ^3.0.0
msw: ^1.0.0
@@ -19347,13 +19347,6 @@ __metadata:
languageName: node
linkType: hard
"@zip.js/zip.js@npm:^2.7.24":
version: 2.7.24
resolution: "@zip.js/zip.js@npm:2.7.24"
checksum: f56f973748d063158cbb6f07ccf4d4c64d35952bb2ecf3d9922db935b17f4e689b6d8568041083195ff4679a0d1a9378fa78adca7428819239d4a3fb4a1dd2d2
languageName: node
linkType: hard
"@zxing/text-encoding@npm:0.9.0":
version: 0.9.0
resolution: "@zxing/text-encoding@npm:0.9.0"
@@ -28415,6 +28408,13 @@ __metadata:
languageName: node
linkType: hard
"immediate@npm:~3.0.5":
version: 3.0.6
resolution: "immediate@npm:3.0.6"
checksum: f9b3486477555997657f70318cc8d3416159f208bec4cca3ff3442fd266bc23f50f0c9bd8547e1371a6b5e82b821ec9a7044a4f7b944798b25aa3cc6d5e63e62
languageName: node
linkType: hard
"immer@npm:9.0.7":
version: 9.0.7
resolution: "immer@npm:9.0.7"
@@ -31066,6 +31066,18 @@ __metadata:
languageName: node
linkType: hard
"jszip@npm:^3.10.1":
version: 3.10.1
resolution: "jszip@npm:3.10.1"
dependencies:
lie: ~3.3.0
pako: ~1.0.2
readable-stream: ~2.3.6
setimmediate: ^1.0.5
checksum: abc77bfbe33e691d4d1ac9c74c8851b5761fba6a6986630864f98d876f3fcc2d36817dfc183779f32c00157b5d53a016796677298272a714ae096dfe6b1c8b60
languageName: node
linkType: hard
"just-diff-apply@npm:^4.0.1":
version: 4.0.1
resolution: "just-diff-apply@npm:4.0.1"
@@ -31402,6 +31414,15 @@ __metadata:
languageName: node
linkType: hard
"lie@npm:~3.3.0":
version: 3.3.0
resolution: "lie@npm:3.3.0"
dependencies:
immediate: ~3.0.5
checksum: 33102302cf19766f97919a6a98d481e01393288b17a6aa1f030a3542031df42736edde8dab29ffdbf90bebeffc48c761eb1d064dc77592ca3ba3556f9fe6d2a8
languageName: node
linkType: hard
"lilconfig@npm:2.1.0, lilconfig@npm:^2.0.3":
version: 2.1.0
resolution: "lilconfig@npm:2.1.0"
@@ -34784,7 +34805,7 @@ __metadata:
languageName: node
linkType: hard
"pako@npm:^1.0.10, pako@npm:~1.0.5":
"pako@npm:^1.0.10, pako@npm:~1.0.2, pako@npm:~1.0.5":
version: 1.0.11
resolution: "pako@npm:1.0.11"
checksum: 1be2bfa1f807608c7538afa15d6f25baa523c30ec870a3228a89579e474a4d992f4293859524e46d5d87fd30fa17c5edf34dbef0671251d9749820b488660b16
@@ -37609,7 +37630,7 @@ __metadata:
languageName: node
linkType: hard
"readable-stream@npm:^2.0.0, readable-stream@npm:^2.0.1, readable-stream@npm:^2.0.2, readable-stream@npm:^2.0.5, readable-stream@npm:^2.2.2, readable-stream@npm:^2.3.3, readable-stream@npm:^2.3.5, readable-stream@npm:^2.3.6":
"readable-stream@npm:^2.0.0, readable-stream@npm:^2.0.1, readable-stream@npm:^2.0.2, readable-stream@npm:^2.0.5, readable-stream@npm:^2.2.2, readable-stream@npm:^2.3.3, readable-stream@npm:^2.3.5, readable-stream@npm:^2.3.6, readable-stream@npm:~2.3.6":
version: 2.3.8
resolution: "readable-stream@npm:2.3.8"
dependencies: