All Projects → mikbry → anzip

mikbry / anzip

Licence: MIT license
Simple async unzip library for Node.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to anzip

nodekit
[Moved to Codeberg] A Small Web server.
Stars: ✭ 68 (+11.48%)
Mutual labels:  esm
importar
R package to import/load packages or functions the 'Python' way
Stars: ✭ 17 (-72.13%)
Mutual labels:  import
abrute
Multi-threaded AES Brute Force File Decryption
Stars: ✭ 22 (-63.93%)
Mutual labels:  unzip
commercetools-sdk-typescript
The e-commerce SDK from commercetools for JavaScript written in TypeScript.
Stars: ✭ 25 (-59.02%)
Mutual labels:  import
qgis-kmltools-plugin
Fast KML Import and Export Plugin for QGIS
Stars: ✭ 45 (-26.23%)
Mutual labels:  import
extract-files
A function to recursively extract files and their object paths within a value, replacing them with null in a deep clone without mutating the original value. FileList instances are treated as File instance arrays. Files are typically File and Blob instances.
Stars: ✭ 48 (-21.31%)
Mutual labels:  esm
great-migration
Copy objects from Rackspace to S3
Stars: ✭ 15 (-75.41%)
Mutual labels:  import
meteor-graphql
Compiler plugin that supports GraphQL files in Meteor
Stars: ✭ 56 (-8.2%)
Mutual labels:  import
konan
find all require/import calls by walking the AST
Stars: ✭ 48 (-21.31%)
Mutual labels:  import
unzip
Tiny unzip helper class for .NET 3.5 Client Profile and Mono 2.10, written in pure C#.
Stars: ✭ 25 (-59.02%)
Mutual labels:  unzip
import-cli-simple
This the meta package for Pacemaker Community, a Symfony based CLI application that provides import functionality for products, categories, attributes, and attribute-sets. The default format is CSV, adapters for XML are also available. The application can be declaratively extended by additional operations, which can be used to reassemble and exe…
Stars: ✭ 69 (+13.11%)
Mutual labels:  import
excel mysql
Module for import Excel files to MySQL table and export MySQL table to Excel file using PHPExcel
Stars: ✭ 30 (-50.82%)
Mutual labels:  import
lint-deps
Lint for unused or missing dependencies in your node.js projects. Customize with plugins or configuration.
Stars: ✭ 48 (-21.31%)
Mutual labels:  import
oletus
Minimal ECMAScript Module test runner
Stars: ✭ 43 (-29.51%)
Mutual labels:  esm
xv
❌ ✔️ zero-config test runner for simple projects
Stars: ✭ 588 (+863.93%)
Mutual labels:  esm
tape-es
ESM-compatible Tape.js test runner
Stars: ✭ 24 (-60.66%)
Mutual labels:  esm
VBA-Import-Export
Export & Import VBA code for use with Git (or any VCS)
Stars: ✭ 14 (-77.05%)
Mutual labels:  import
webpacker
🔸 Webpack configuration manager
Stars: ✭ 18 (-70.49%)
Mutual labels:  esm
babel-loader-lerna-cra
Transpile Create-React-App imports in Lerna projects.
Stars: ✭ 30 (-50.82%)
Mutual labels:  import
janusgraph-util
util for janusgraph to import data and so on/Janusgraph 导数据等工具
Stars: ✭ 72 (+18.03%)
Mutual labels:  import

Anzip

Build Status codecov NPM version License

Anzip is a library to unzip file archive for Node using only one async function.

Purpose

  • Simple to use
  • Modern ES6+ syntax (import instead of require, await/async, ...)
  • Unzip by Yauzl
  • Follows Node best practices

Requirements

  • Node >= 12

Install

yarn add anzip

Or using npm

npm add anzip

Usage

Now that ESM support is widely common, require should be forgotten.

import anzip from 'anzip';

Extract file.zip to current path

await anzip('file.zip');

Extract file.zip to the current path and get output

const output = await anzip('file.zip');
console.log('duration=', output.duration);
console.log('number of files=', output.files.length);

Extract only README.md from file.zip to current path

const output = await anzip('file.zip', { pattern: 'README.md', });
console.log('duration=', output.duration);
console.log('number of files=', output.files.length); // Should be one

Extract only README.md from file.zip to output content variable

const output = await anzip('file.zip', { pattern: 'README.md', outputContent: true });
console.log('duration=', output.duration);
console.log('content=', output.files[0].content);

Extract only README.md from file.zip to output content variable and currentpath

const output = await anzip('file.zip', { pattern: 'README.md', outputPath: './', outputContent: true });
console.log('duration=', output.duration);
console.log('content=', output.files[0].content);

Extract with an entryHandler to fliter entry

const outputPath = './path';
const entryHandler = async entry => {
  let resp = true;
  const fn = entry.name;
  if (fn.endsWith('dummy.pdf')) {
    try {
      await entry.saveTo(outputPath);
      resp = false;
    } catch (e) {
      //
    }
  }
  return resp;
};
const output = await anzip('file.zip',
    outputPath,
    { pattern: /(^(?!\.))(.+(.png|.jpeg|.jpg|.svg|.pdf|.json))$/i,, outputPath: './', entryHandler, outputContent: true });
console.log('duration=', output.duration);
// ./path/dummy.pdf should be saved

Extract using 2 rules and an entryHandler in one to fliter entry

const outputPath = './path';
const entryHandler = async entry => {
  let resp = true;
  const fn = entry.name;
  if (fn.endsWith('dummy.pdf')) {
    try {
      await entry.saveTo(outputPath);
      resp = false;
    } catch (e) {
      //
    }
  }
  return resp;
};
const output = await anzip('file.zip',
    outputPath,
    pattern: /(^(?!\.))(.+(.png|.jpeg|.jpg|.svg|.pdf|.json))$/i,
    flattenPath: true,
    disableSave: true,
    disableOutput: true,
    rules: [
      { pattern: /(^(?!\.))(test.json)$/i, outputContent: true },
      { pattern: /(^(?!\.))(.+(.png|.jpeg|.jpg|.svg|.pdf))$/i, entryHandler },
    ],
  });
console.log('duration=', output.duration);
// ./path/dummy.pdf should be saved

Documentation

One function to rule them all.

output = await anzip(filename, {opts})

Function properties

parameters type description
filename mandatory string containing zip path to + file
opts optional object containing optional parameters
opts.outputPath optional string the directory where to to save extracted files
opts.outputContent optional boolean if set to true, return file.content a Buffer containing file's content
opts.disableSave optional boolean if set to true, don't save files
opts.pattern optional regex if set only extract/proceed matching filenames
opts.flattenPath optional boolean if set don't recreate zip's directories, all file are saved in outputPath
opts.disableOutput optional boolean if set don't write files to output
opts.entryHandler optional promise use it to add some extra processing to an entry, return true if stream is consumed otherwise false
opts.rules optional array use it to add some fine tuned control how to handle each files
opts.rules.pattern mandatory regex if it match entry will use rule's parameters instead of global's one

Returned output is an object containing:

parameters type description
duration number how long it took to extract in seconds
files array all files extracted or handled, otherwise empty
files[x].name string the filename
files[x].directory string the directory in archive (even if opts.flattenPath=true)
files[x].saved boolean true if the file was saved to outputPath
files[x].content Buffer the content of the file available if opts.outputContent=true or rule.outputContent=true
files[x].error Error if an error occured

Contribution

Read Contributing Guide for development setup instructions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].