0.0.1 • Published 5 years ago

web-zip-stream v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

web-zip-stream

npm install @trd-clarkdwain/web-zip-stream

generate zip stream in the browser using whatwg streams which you can read and write

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/web-streams-polyfill@2.0.2/dist/polyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/streamsaver@2.0.3/StreamSaver.min.js"></script>
<script type="module">
    import WebZipStream from 'https://cdn.jsdelivr.net/npm/@trd-clarkdwain/web-zip-stream@1.0.0/src/index.min.js'
    window.download = function download() {
        const fileStream = streamSaver.createWriteStream('web-zip-stream.zip');
        const inputFileElement = document.getElementById('input');
        const fileList = [...inputFileElement.files];
        if (fileList.length === 0) return false;

        const zip = new WebZipStream();

        for (let file of fileList) {
            zip.file(file);
        }

        zip.pipe(fileStream)
    }
</script>
<div>
    <h3>WEB ZIP STREAM</h3>
    <input type="file" id="input" multiple> <br><br>
    <button onclick="download()">download</button>
</div>
</body>
</html>