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

yazl

Package Overview
Dependencies
Maintainers
0
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yazl

yet another zip library for node

  • 3.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created

What is yazl?

The yazl npm package is a library for creating ZIP archives in a straightforward and efficient manner. It allows you to add files, directories, and even raw data to a ZIP archive, and then output the archive to a writable stream.

What are yazl's main functionalities?

Creating a ZIP Archive

This feature allows you to create a ZIP archive and add a file to it. The code sample demonstrates how to add a file from the filesystem to the ZIP archive and then write the archive to a file named 'output.zip'.

const yazl = require('yazl');
const fs = require('fs');

let zipfile = new yazl.ZipFile();
zipfile.addFile('path/to/file.txt', 'file.txt');
zipfile.outputStream.pipe(fs.createWriteStream('output.zip')).on('close', function() {
  console.log('ZIP file created successfully');
});
zipfile.end();

Adding a Directory to a ZIP Archive

This feature allows you to add an entire directory to a ZIP archive. The code sample demonstrates how to recursively add all files and subdirectories from a specified directory to the ZIP archive.

const yazl = require('yazl');
const fs = require('fs');
const path = require('path');

let zipfile = new yazl.ZipFile();

function addDirectoryToZip(zipfile, dirPath, zipPath) {
  fs.readdirSync(dirPath).forEach(file => {
    const fullPath = path.join(dirPath, file);
    const zipFilePath = path.join(zipPath, file);
    if (fs.statSync(fullPath).isDirectory()) {
      addDirectoryToZip(zipfile, fullPath, zipFilePath);
    } else {
      zipfile.addFile(fullPath, zipFilePath);
    }
  });
}

addDirectoryToZip(zipfile, 'path/to/directory', 'directory');
zipfile.outputStream.pipe(fs.createWriteStream('output.zip')).on('close', function() {
  console.log('ZIP file created successfully');
});
zipfile.end();

Adding Raw Data to a ZIP Archive

This feature allows you to add raw data to a ZIP archive. The code sample demonstrates how to create a buffer from a string and add it to the ZIP archive as a file named 'hello.txt'.

const yazl = require('yazl');
const fs = require('fs');

let zipfile = new yazl.ZipFile();
let rawData = Buffer.from('Hello, world!', 'utf-8');
zipfile.addBuffer(rawData, 'hello.txt');
zipfile.outputStream.pipe(fs.createWriteStream('output.zip')).on('close', function() {
  console.log('ZIP file created successfully');
});
zipfile.end();

Other packages similar to yazl

Keywords

FAQs

Package last updated on 23 Nov 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