How to use yauzl - 10 common examples

To help you get started, we’ve selected a few yauzl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github orangewise / s3-zip / test / test-s3-zip-alt-names.js View on Github external
archive.on('close', function () {
    console.log('+++++++++++')
    yauzl.open(join(__dirname, '/test-alt.zip'), function (err, zip) {
      if (err) console.log('err', err)
      zip.on('entry', function (entry) {
        // console.log(entry);
        child.same(entry.fileName, file1Alt)
        child.same(entry.compressedSize, 11)
        child.same(entry.uncompressedSize, 20)
      })

      zip.on('close', function () {
        child.end()
      })
    })
  })
  child.type(archive, 'object')
github hanhdt / esp32-flash-tool / src / main / unzip_image.js View on Github external
export default function processCompressedFile (mainWindow, zipParams) {
  yauzl.open(zipParams.filePath, zipParams.options, (err, zipFile) => {
    if (err) throw err

    zipFile.on('error', (err) => {
      throw err
    })

    zipFile.on('entry', (entry) => {
      // console.log('File:', entry.fileName)
      zipFile.openReadStream(entry, (err, readStream) => {
        if (err) throw err

        if (zipParams.target === entry.fileName) {
          saveFile(mainWindow, zipParams, entry.fileName, readStream)
        }
      })
    })
github electrode-io / electrode-native / ern-core / src / unzip.ts View on Github external
return new Promise((resolve, reject) => {
    yauzl.fromBuffer(zippedData, { lazyEntries: true }, (err, zipfile) => {
      if (err) {
        reject(err)
      } else if (zipfile == null) {
        reject(new Error('zipFile is null or undefined'))
      } else {
        zipfile.readEntry()
        zipfile.on('end', () => resolve())
        zipfile.on('entry', entry => {
          if (/\$/.test(entry.fileName)) {
            // Current entry is an empty directory
            shell.mkdir('-p', path.join(destPath, entry.fileName))
            zipfile.readEntry()
          } else {
            // Current entry is a file
            shell.mkdir('-p', path.join(destPath, path.dirname(entry.fileName)))
            const ws = fs.createWriteStream(path.join(destPath, entry.fileName))
github TimelordUK / jspurefix / src / util / unzip.js View on Github external
// resolve optional parameters
      if (offsetArg == null) offsetArg = 0
      if (lenArg == null && endArg == null) endArg = stats.size
      if (endArg == null) endArg = lenArg + offsetArg
      else if (endArg < 0) endArg = stats.size + endArg
      // validate parameters
      if (offsetArg < 0) throw new Error('--offset < 0')
      if (lenArg < 0) throw new Error('--len < 0')
      if (offsetArg > endArg) throw new Error('--offset > --end')
      if (endArg > stats.size) throw new Error('--end/--len goes past EOF')

      // extend RandomAccessReader
      function MiddleOfFileReader () {
        yauzl.RandomAccessReader.call(this)
      }
      util.inherits(MiddleOfFileReader, yauzl.RandomAccessReader)
      // implement required and option methods
      MiddleOfFileReader.prototype._readStreamForRange = function (start, end) {
        return fs.createReadStream(null, {
          fd: fd,
          // shift the start and end offsets
          start: start + offsetArg,
          end: end + offsetArg - 1, // the -1 is because fs.createReadStream()'s end option is inclusive
          autoClose: false
        })
      }
      MiddleOfFileReader.prototype.read = function (buffer, offset, length, position, callback) {
        // shift the position
        fs.read(fd, buffer, offset, length, position + offsetArg, callback)
      }
      MiddleOfFileReader.prototype.close = function (callback) {
        fs.close(fd, callback)
github walletpass / pass-js / src / lib / yazul-promisified.ts View on Github external
writable: false,
    configurable: false,
    value() {
      return new EventIterator((push, stop, fail) => {
        this.addListener('entry', push);
        this.addListener('end', stop);
        this.addListener('error', fail);
      })[Symbol.asyncIterator]();
    },
  },
  openReadStreamAsync: {
    enumerable: true,
    writable: false,
    configurable: false,
    // eslint-disable-next-line @typescript-eslint/unbound-method
    value: promisify(ZipFile.prototype.openReadStream),
  },
  getBuffer: {
    enumerable: true,
    writable: false,
    configurable: false,
    async value(entry: Entry) {
      const stream = await this.openReadStreamAsync(entry);
      return streamToBuffer(stream);
    },
  },
});
export const unzipBuffer = (promisify(ZipFromBuffer) as unknown) as (
  buffer: Buffer,
  options?: Options,
) => Promise<
  ZipFile & {
github walletpass / pass-js / src / lib / yazul-promisified.ts View on Github external
import { promisify } from 'util';

import { Entry, Options, ZipFile, fromBuffer as ZipFromBuffer } from 'yauzl';
import { EventIterator } from 'event-iterator';

import { streamToBuffer } from './stream-to-buffer';

// Promisifying yauzl
Object.defineProperties(ZipFile.prototype, {
  [Symbol.asyncIterator]: {
    enumerable: true,
    writable: false,
    configurable: false,
    value() {
      return new EventIterator((push, stop, fail) => {
        this.addListener('entry', push);
        this.addListener('end', stop);
        this.addListener('error', fail);
      })[Symbol.asyncIterator]();
    },
  },
  openReadStreamAsync: {
    enumerable: true,
    writable: false,
    configurable: false,
github TimelordUK / jspurefix / src / util / unzip.js View on Github external
fd: fd,
          // shift the start and end offsets
          start: start + offsetArg,
          end: end + offsetArg - 1, // the -1 is because fs.createReadStream()'s end option is inclusive
          autoClose: false
        })
      }
      MiddleOfFileReader.prototype.read = function (buffer, offset, length, position, callback) {
        // shift the position
        fs.read(fd, buffer, offset, length, position + offsetArg, callback)
      }
      MiddleOfFileReader.prototype.close = function (callback) {
        fs.close(fd, callback)
      }

      yauzl.fromRandomAccessReader(new MiddleOfFileReader(), endArg - offsetArg, options, handleZipFile)
    })
  })
github cjihrig / zipit / test / index.js View on Github external
function unzip (buffer, callback) {
  const result = { files: {} };

  Unzip.fromBuffer(buffer, (err, zip) => {
    if (err) {
      return callback(err);
    }

    zip.on('error', function onError (err) {
      zip.close();
      callback(err);
    });

    zip.on('end', function onEnd () {
      zip.close();
    });

    if (zip.entryCount === 0) {
      return callback(null, result);
    }
github perliedman / node-hgt / src / imagico.js View on Github external
return new Promise(function(fulfill, reject) {
        var unzips = [];

        yauzl.open(zipPath, function(err, zipfile) {
            if (err) {
                reject(err);
                return;
            }
            zipfile
            .on('entry', function(entry) {
                if (/\/$/.test(entry.fileName)) {
                    return;
                }
                zipfile.openReadStream(entry, function(err, readStream) {
                    var lastSlashIdx = entry.fileName.lastIndexOf('/'),
                        fileName = entry.fileName.substr(lastSlashIdx + 1),
                        filePath = path.join(targetPath, fileName);
                    if (err) {
                        reject(err);
                        return;
github PublicI / fec-loader / src / util / fec / unzip.js View on Github external
function unzipFile(file,cb) {
    console.log(file);

    yauzl.open(file, {
            autoClose: false
        }, function(err, zipfile) {
        if (err) throw err;

        filingQueue.drain = null;

        zipfile.on('entry', function(entry) {
            if (entry.fileName.indexOf('.fec') !== -1) {

                filingQueue.push({
                    name: entry.fileName,
                    openStream: function (cb) {
                        zipfile.openReadStream(entry, cb);
                    }
                });