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

zip-stream

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zip-stream

a streaming zip archive generator.

  • 7.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.5M
decreased by-7.39%
Maintainers
1
Weekly downloads
 
Created

What is zip-stream?

The zip-stream npm package is a streaming zip archive generator. It allows you to compress files and directories on the fly and stream them to the user or save them to disk. It is particularly useful for creating zip files without having to store the entire contents in memory or on disk before sending to the recipient.

What are zip-stream's main functionalities?

Creating a zip archive

This code sample demonstrates how to create a simple zip archive containing a single file with the text 'Hello World!' and the file name 'hello.txt'. The archive is then written to 'path/to/archive.zip'.

const ZipStream = require('zip-stream');
const fs = require('fs');

const archive = new ZipStream();
const output = fs.createWriteStream('path/to/archive.zip');

archive.pipe(output);

archive.entry('Hello World!', { name: 'hello.txt' }, function(err) {
  if (err) throw err;
  archive.finish();
});

Adding files to a zip archive from a stream

This code sample shows how to add a file to a zip archive from a readable stream. The file 'path/to/file.txt' is streamed and added to the archive under the name 'file.txt'.

const ZipStream = require('zip-stream');
const fs = require('fs');

const archive = new ZipStream();
const output = fs.createWriteStream('path/to/archive.zip');
const fileStream = fs.createReadStream('path/to/file.txt');

archive.pipe(output);

archive.entry(fileStream, { name: 'file.txt' }, function(err) {
  if (err) throw err;
  archive.finish();
});

Adding multiple files and directories

This code sample illustrates how to add multiple files and directories to a zip archive. It adds 'file1.txt' with direct content, streams 'file2.txt' from the file system, and includes an entire directory 'path/to/directory' under the name 'directory' in the archive.

const ZipStream = require('zip-stream');
const fs = require('fs');

const archive = new ZipStream();
const output = fs.createWriteStream('path/to/archive.zip');

archive.pipe(output);

archive.entry('File content', { name: 'file1.txt' }, function(err) {
  if (err) throw err;
  archive.entry(fs.createReadStream('path/to/file2.txt'), { name: 'file2.txt' }, function(err) {
    if (err) throw err;
    archive.directory('path/to/directory', 'directory', function(err) {
      if (err) throw err;
      archive.finish();
    });
  });
});

Other packages similar to zip-stream

Keywords

FAQs

Package last updated on 16 Oct 2024

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