Skip to content

Commit

Permalink
enhance: use littlezipper instead of jszip
Browse files Browse the repository at this point in the history
it's very lightweight, and uses the built-in `CompressionStream` for compression (available in CF Workers)
  • Loading branch information
marcelgerber authored and danyx23 committed Oct 10, 2024
1 parent abe4ce4 commit abf0d94
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 53 deletions.
20 changes: 11 additions & 9 deletions functions/_common/grapherRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { constructReadme } from "./readmeTools"
import { svg2png, initialize as initializeSvg2Png } from "svg2png-wasm"
import { TimeLogger } from "./timeLogger"
import { png, StatusError } from "itty-router"
import JSZip from "jszip"
import { createZip, File } from "littlezipper"

import svg2png_wasm from "../../node_modules/svg2png-wasm/svg2png_wasm_bg.wasm"

Expand Down Expand Up @@ -544,14 +544,16 @@ export async function fetchZipForGrapher(
const readme = assembleReadme(grapher)
const csv = assembleCsv(grapher, searchParams)
console.log("Fetched the parts, creating zip file")
const zip = new JSZip()
zip.file(
`${identifier.id}.metadata.json`,
JSON.stringify(metadata, undefined, 2)
)
zip.file(`${identifier.id}.csv`, csv)
zip.file("readme.md", readme)
const content = await zip.generateAsync({ type: "arraybuffer" })

const zipContent: File[] = [
{
path: `${identifier.id}.metadata.json`,
data: JSON.stringify(metadata, undefined, 2),
},
{ path: `${identifier.id}.csv`, data: csv },
{ path: "readme.md", data: readme },
]
const content = await createZip(zipContent)
console.log("Generated content, returning response")
return new Response(content, {
headers: {
Expand Down
2 changes: 1 addition & 1 deletion functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"@ourworldindata/grapher": "workspace:^",
"@ourworldindata/utils": "workspace:^",
"itty-router": "^5.0.17",
"jszip": "^3.10.1",
"littlezipper": "^0.1.4",
"stripe": "^14.20.0",
"svg2png-wasm": "^1.4.1"
},
Expand Down
51 changes: 8 additions & 43 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11583,13 +11583,6 @@ __metadata:
languageName: node
linkType: hard

"immediate@npm:~3.0.5":
version: 3.0.6
resolution: "immediate@npm:3.0.6"
checksum: 10/f9b3486477555997657f70318cc8d3416159f208bec4cca3ff3442fd266bc23f50f0c9bd8547e1371a6b5e82b821ec9a7044a4f7b944798b25aa3cc6d5e63e62
languageName: node
linkType: hard

"immutable@npm:^4.0.0, immutable@npm:^4.3.6":
version: 4.3.6
resolution: "immutable@npm:4.3.6"
Expand Down Expand Up @@ -13209,18 +13202,6 @@ __metadata:
languageName: node
linkType: hard

"jszip@npm:^3.10.1":
version: 3.10.1
resolution: "jszip@npm:3.10.1"
dependencies:
lie: "npm:~3.3.0"
pako: "npm:~1.0.2"
readable-stream: "npm:~2.3.6"
setimmediate: "npm:^1.0.5"
checksum: 10/bfbfbb9b0a27121330ac46ab9cdb3b4812433faa9ba4a54742c87ca441e31a6194ff70ae12acefa5fe25406c432290e68003900541d948a169b23d30c34dd984
languageName: node
linkType: hard

"just-diff-apply@npm:^5.2.0":
version: 5.5.0
resolution: "just-diff-apply@npm:5.5.0"
Expand Down Expand Up @@ -13486,15 +13467,6 @@ __metadata:
languageName: node
linkType: hard

"lie@npm:~3.3.0":
version: 3.3.0
resolution: "lie@npm:3.3.0"
dependencies:
immediate: "npm:~3.0.5"
checksum: 10/f335ce67fe221af496185d7ce39c8321304adb701e122942c495f4f72dcee8803f9315ee572f5f8e8b08b9e8d7195da91b9fad776e8864746ba8b5e910adf76e
languageName: node
linkType: hard

"lilconfig@npm:3.0.0":
version: 3.0.0
resolution: "lilconfig@npm:3.0.0"
Expand Down Expand Up @@ -13578,6 +13550,13 @@ __metadata:
languageName: node
linkType: hard

"littlezipper@npm:^0.1.4":
version: 0.1.4
resolution: "littlezipper@npm:0.1.4"
checksum: 10/72b14b035a4cd2b5ac9999b955c5f17dcfa67859d83857f1c90d82a70cea4980cdc894915a8f94ed215cb5d207fcd64aa358081581349a167f7e2a261e3c5a04
languageName: node
linkType: hard

"load-json-file@npm:6.2.0":
version: 6.2.0
resolution: "load-json-file@npm:6.2.0"
Expand Down Expand Up @@ -15297,7 +15276,7 @@ __metadata:
"@ourworldindata/grapher": "workspace:^"
"@ourworldindata/utils": "workspace:^"
itty-router: "npm:^5.0.17"
jszip: "npm:^3.10.1"
littlezipper: "npm:^0.1.4"
stripe: "npm:^14.20.0"
svg2png-wasm: "npm:^1.4.1"
languageName: unknown
Expand Down Expand Up @@ -15473,13 +15452,6 @@ __metadata:
languageName: node
linkType: hard

"pako@npm:~1.0.2":
version: 1.0.11
resolution: "pako@npm:1.0.11"
checksum: 10/1ad07210e894472685564c4d39a08717e84c2a68a70d3c1d9e657d32394ef1670e22972a433cbfe48976cb98b154ba06855dcd3fcfba77f60f1777634bec48c0
languageName: node
linkType: hard

"papaparse@npm:^5.3.1":
version: 5.3.1
resolution: "papaparse@npm:5.3.1"
Expand Down Expand Up @@ -18080,13 +18052,6 @@ __metadata:
languageName: node
linkType: hard

"setimmediate@npm:^1.0.5":
version: 1.0.5
resolution: "setimmediate@npm:1.0.5"
checksum: 10/76e3f5d7f4b581b6100ff819761f04a984fa3f3990e72a6554b57188ded53efce2d3d6c0932c10f810b7c59414f85e2ab3c11521877d1dea1ce0b56dc906f485
languageName: node
linkType: hard

"setprototypeof@npm:1.2.0":
version: 1.2.0
resolution: "setprototypeof@npm:1.2.0"
Expand Down

0 comments on commit abf0d94

Please sign in to comment.