How to use the yauzl.fromBuffer function in yauzl

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 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 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 node-modules / compressing / lib / zip / uncompress_stream.js View on Github external
      .then(buf => yauzl.fromBuffer(buf, yauzlOpts, this[YAUZL_CALLBACK]))
      .catch(e => this.emit('error', e));
github superpowers / superpowers-app / src / renderer / updateManager.ts View on Github external
res.on("end", () => {
        const zipBuffer = Buffer.concat(buffers);

        yauzl.fromBuffer(zipBuffer, { lazyEntries: true }, (err: Error, zipFile: any) => {
          if (err != null) throw err;

          splashScreen.setProgressMax(zipFile.entryCount * 2);
          splashScreen.setProgressValue(zipFile.entryCount);
          let entriesProcessed = 0;

          const rootFolderName = path.parse(downloadURL).name;

          zipFile.readEntry();
          zipFile.on("entry", (entry: any) => {
            if (entry.fileName.indexOf(rootFolderName) !== 0) throw new Error(`Found file outside of root folder: ${entry.fileName} (${rootFolderName})`);

            const filename = path.join(settings.corePath, entry.fileName.replace(rootFolderName, ""));
            if (/\/$/.test(entry.fileName)) {
              mkdirp(filename, (err) => {
                if (err != null) throw err;
github superpowers / superpowers-core / server / commands / utils.ts View on Github external
res.on("end", () => {
      let zipBuffer = Buffer.concat(buffers);

      yauzl.fromBuffer(zipBuffer, { lazyEntries: true }, (err: Error, zipFile: any) => {
        if (err != null) throw err;

        progress = zipFile.entryCount;
        progressMax = zipFile.entryCount * 2;

        let rootFolderName: string;

        zipFile.readEntry();
        zipFile.on("entry", (entry: any) => {
          if (rootFolderName == null) rootFolderName = entry.fileName;

          if (entry.fileName.indexOf(rootFolderName) !== 0) throw new Error(`Found file outside of root folder: ${entry.fileName} (${rootFolderName})`);

          const filename = path.join(downloadPath, entry.fileName.replace(rootFolderName, ""));
          if (/\/$/.test(entry.fileName)) {
            mkdirp(filename, (err) => {
github NanoAdblocker / NanoCore2 / term / crowdin.js View on Github external
await new Promise((resolve, reject) => {
        const done = new Set();

        yauzl.fromBuffer(file, { lazyEntries: true }, (err, zip) => {
            if (err)
                return void reject(err);

            const next = () => {
                zip.readEntry();
            };

            zip.on("entry", (entry) => {
                const name = entry.fileName;

                if (name.endsWith("/"))
                    return void next();

                const [key, messages, ...rest] = name.split("/");

                if (messages !== "messages.json" || rest.length !== 0)
github node-modules / compressing / lib / zip / uncompress_stream.js View on Github external
if (this._zipFileNameEncoding === 'utf-8') {
      this._zipFileNameEncoding = 'utf8';
    }

    this[YAUZL_CALLBACK] = this[YAUZL_CALLBACK].bind(this);

    const sourceType = utils.sourceType(opts.source);

    const yauzlOpts = this._yauzlOpts = Object.assign({}, DEFAULTS, opts.yauzl);
    if (sourceType === 'file') {
      yauzl.open(opts.source, yauzlOpts, this[YAUZL_CALLBACK]);
      return;
    }

    if (sourceType === 'buffer') {
      yauzl.fromBuffer(opts.source, yauzlOpts, this[YAUZL_CALLBACK]);
      return;
    }

    if (sourceType === 'stream') {
      utils.streamToBuffer(opts.source)
      .then(buf => yauzl.fromBuffer(buf, yauzlOpts, this[YAUZL_CALLBACK]))
      .catch(e => this.emit('error', e));
      return;
    }

    this.on('pipe', srcStream => {
      srcStream.unpipe(srcStream);

      utils.streamToBuffer(srcStream)
      .then(buf => {
        this._chunks.push(buf);
github pedromsilvapt / unicast / src / Subtitles / Providers / OpenSubtitles / OpenSubtitlesProvider.ts View on Github external
let result = new Promise( ( resolve, reject ) => {
            yauzl.fromBuffer( content.body, { lazyEntries: true }, ( err, file ) => {
                try {
                    if ( err ) {
                        return reject( err );
                    }

                    if ( file.entryCount > 100 ) {
                        return reject( new Error( `Too many files in the zip "${ file.entryCount }".` ) );
                    }
    
                    let foundSubs : boolean = false;
                    
                    file.readEntry();
    
                    file.on( 'entry', entry => {
                        if ( isSubtitle( entry.fileName ) ) {
                            file.openReadStream( entry, ( err, stream : NodeJS.ReadableStream ) => {
github microsoft / Windows-Machine-Learning / Tools / WinMLDashboard / src / native / python.tsx View on Github external
return new Promise((resolve, reject) => {
        yauzl.fromBuffer(buffer, (err, zipfile) => {
            if (err) {
                return reject(err);
            }
            zipfile!.once('end', resolve);
            zipfile!.once('error', reject);
            zipfile!.on('entry', entry => {
                const destination = path.join(directory, entry.fileName);
                if (entry.fileName.endsWith('/')) {
                    if (fs.existsSync(destination)) {
                        return;
                    }
                    try {
                        return fs.mkdirSync(destination);
                    } catch (e) {
                        return reject(e);
                    }