What is pizzip?
Pizzip is a JavaScript library for creating, reading, and editing zip files in the browser or Node.js. It is particularly useful for handling Office Open XML files, such as .docx, .xlsx, and .pptx, which are essentially zip files containing XML documents.
What are pizzip's main functionalities?
Create a new zip file
This feature allows you to create a new zip file and add files to it. In this example, a new zip file is created, and a text file named 'hello.txt' with the content 'Hello, World!' is added to it.
const PizZip = require('pizzip');
const zip = new PizZip();
zip.file('hello.txt', 'Hello, World!');
const content = zip.generate({ type: 'nodebuffer' });
Read a zip file
This feature allows you to read an existing zip file. In this example, a zip file named 'example.zip' is read, and the content of the file 'hello.txt' within the zip is extracted as text.
const PizZip = require('pizzip');
const fs = require('fs');
const data = fs.readFileSync('example.zip');
const zip = new PizZip(data);
const fileContent = zip.file('hello.txt').asText();
Modify a file within a zip
This feature allows you to modify the content of a file within an existing zip file. In this example, the content of 'hello.txt' within 'example.zip' is changed to 'Modified content'.
const PizZip = require('pizzip');
const fs = require('fs');
const data = fs.readFileSync('example.zip');
const zip = new PizZip(data);
zip.file('hello.txt', 'Modified content');
const newContent = zip.generate({ type: 'nodebuffer' });
Other packages similar to pizzip
jszip
JSZip is a library for creating, reading, and editing zip files in JavaScript. It is similar to Pizzip in functionality, offering a wide range of features for handling zip files. JSZip is widely used and has a large community, making it a robust choice for zip file manipulation.
adm-zip
ADM-ZIP is a pure JavaScript implementation for zip file management with support for reading, creating, and updating zip files. It is similar to Pizzip but is often used in Node.js environments due to its synchronous API, which can be more straightforward for server-side applications.
PizZip
PizZip is a fork of JSZip version 2.x, because we want a synchronous Zip library.
A library for creating, reading and editing .zip files with Javascript, with a lovely and simple API.
var zip = new PizZip();
zip.file("Hello.txt", "Hello World\n");
var img = zip.folder("images");
img.file("smile.gif", imgData, { base64: true });
var content = zip.generate({ type: "blob" });
saveAs(content, "example.zip");
License
PizZip is dual-licensed. You may use it under the MIT license or the GPLv3 license. See LICENSE.markdown.
v3.1.6
Improve typescript support :
Fixes following error message :
error TS1259: Module 'pizzip' can only be default-imported using the 'allowSyntheticDefaultImports' flag
Error - 'tsc' sub task errored after 2.66 s