Skip to content

ewwink/unzipjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

unzipjs

Simple javascript library to Unzip/decompress a zipped file in Browser or Node.js.

I use this on Cloudflare workers because CF not natively support node.js, even you can install node zip library on CF it produce large bundled file, around 300 kB.

The method return array of object

[
  {
    name: "filename", 
    buffer: arrayBuffer, 
    toString: function() // convert buffer to string
  }
]

Installation

Download the files in dist directory

Browser

<script src="unzipjs.min.js"></script>

Nodejs

const unzipjs = require("/.unzipjs")
# or
import unzipjs from "/.unzipjs"

Unzip File

const fs = equire("fs")
const arraybuffer = fs.readFileSync('localfile.zip')

Unzip HTTP Response buffer

const arraybuffer = await fetch('https://example/file.zip').then(
  res => res.arrayBuffer()
);

Then

let unzipped = unzipjs.parse(arraybuffer);
for (let item of unzipped) {
   console.log(item.name)
   console.log(item.toString()) // if file not valid UTF8 return empty 
   console.log(item.buffer.length)
}

Limitation

  • No create .zip function
  • No save to file function

credit: UZIP

About

2 kB Unzip (decompress) library for Javascript, no external dependency, work in Browser and Node.js

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published