@quyse/client-zip
Version:
A tiny and fast client-side streaming ZIP generator
45 lines (37 loc) • 1.25 kB
HTML
<html>
<head>
<meta charset="UTF-8">
<title>Bundler.js test</title>
<style>
html { height: 100%; font-size: 16px; }
body { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; }
button { font-size: inherit; }
</style>
</head>
<body>
<button>Download a few files in one ZIP</button>
<p>(including two strings a file fetched from GitHub)</p>
<script type="module" async>
import { downloadZip } from "../index.js";
async function test() {
// an ArrayBuffer
const hi = new TextEncoder().encode("hello world!")
// an HTTP Response
const code = await fetch("https://raw.githubusercontent.com/Touffy/client-zip/master/src/index.ts")
// just a string
const bye = "goodbye."
const blob = await downloadZip([
{ name: "hello.txt", lastModified: new Date(), input: hi },
code, // you don't need to specify a name and modified date for Responses and Files
{ name: "goodbye.txt", lastModified: new Date(), input: bye }
]).blob()
const link = document.createElement("a")
link.href = URL.createObjectURL(blob)
link.download = "hello+goodbye.zip"
link.click()
}
document.getElementsByTagName("button")[0].onclick = test
</script>
</body>
</html>