Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jszip

Package Overview
Dependencies
Maintainers
3
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jszip

Create, read and edit .zip files with JavaScript http://stuartk.com/jszip

  • 3.10.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.1M
increased by3.09%
Maintainers
3
Weekly downloads
 
Created

What is jszip?

The jszip npm package is a library for creating, reading, and editing .zip files with JavaScript. It allows for the manipulation of zip files directly in the browser or in a Node.js environment. With jszip, users can generate new zip files, add files and folders to them, extract their contents, and more.

What are jszip's main functionalities?

Creating a new zip file

This code creates a new zip file with a single file 'Hello.txt' containing the text 'Hello World' and saves it as 'example.zip'.

const JSZip = require('jszip');
const zip = new JSZip();
zip.file('Hello.txt', 'Hello World');
zip.generateAsync({type: 'nodebuffer'}).then(function(content) {
  require('fs').writeFileSync('example.zip', content);
});

Adding a folder and files

This code adds a folder named 'images' to the zip file and then adds a file 'smile.gif' with base64 encoded image data to this folder.

const JSZip = require('jszip');
const zip = new JSZip();
const imgFolder = zip.folder('images');
imgFolder.file('smile.gif', imgData, {base64: true});
zip.generateAsync({type: 'nodebuffer'}).then(function(content) {
  require('fs').writeFileSync('example.zip', content);
});

Reading a zip file

This code reads an existing zip file 'example.zip' and logs the names of all files contained within it.

const JSZip = require('jszip');
const fs = require('fs');
const zip = new JSZip();
fs.readFile('example.zip', function(err, data) {
  if (err) throw err;
  zip.loadAsync(data).then(function(contents) {
    Object.keys(contents.files).forEach(function(filename) {
      console.log(filename);
    });
  });
});

Extracting a file from a zip

This code extracts the content of the file 'Hello.txt' from the zip file 'example.zip' and logs it to the console.

const JSZip = require('jszip');
const fs = require('fs');
const zip = new JSZip();
fs.readFile('example.zip', function(err, data) {
  if (err) throw err;
  zip.loadAsync(data).then(function() {
    zip.file('Hello.txt').async('string').then(function(content) {
      console.log(content);
    });
  });
});

Other packages similar to jszip

Keywords

FAQs

Package last updated on 02 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc