Skip to content

Latest commit

History

26 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

node-zip

node-zip - Zip/Unzip files ported from JSZip

Installation

npm install node-zip

Usage

Complete example, zip multiple files

varfs=require('fs');varpath=require('path');// The zip library needs to be instantiated:varzip=newrequire('node-zip')();// You can add multiple files by performing subsequent calls to zip.file();// the first argument is how you want the file to be named inside your zip,// the second is the actual data:zip.file('file1.txt',fs.readFileSync(path.join(__dirname,'file1.txt')));zip.file('file2.txt',fs.readFileSync(path.join(__dirname,'file2.txt')));vardata=zip.generate({base64:false,compression: 'DEFLATE'});// it's important to use *binary* encodefs.writeFileSync('test.zip',data,'binary');

You can also load directly:

require('node-zip');varzip=newJSZip(data,options)...

Zip text into file:

varzip=newrequire('node-zip')();zip.file('test.file','hello there');vardata=zip.generate({base64:false,compression:'DEFLATE'});console.log(data);// ugly data

Unzip:

varzip=newrequire('node-zip')(data,{base64: false,checkCRC32: true});console.log(zip.files['test.file']);// hello there

Write to a file (IMPORTANT: use binary encode, thanks to @Acek)

varfs=require("fs");zip.file('test.txt','hello there');vardata=zip.generate({base64:false,compression:'DEFLATE'});fs.writeFileSync('test.zip',data,'binary');

Testing

npm install -g jasmine-node
jasmine-node test

Manual

node-zip uses JSZip, please refer to their website for further information: http://stuartk.com/jszip/

Contributors

David Duponchel @dduponchel

Feel free to send your pull requests and contribute to this project

License

MIT

About

No description, website, or topics provided.

Resources

Stars

217 stars

Watchers

7 watching

Forks

Releases

Packages

Used by

Contributors

Languages