How to use the unzipper.Extract function in unzipper

To help you get started, we’ve selected a few unzipper 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 serverless / event-gateway-sdk / tests / utils / eventGatewayDownload.js View on Github external
return new Promise((resolve, reject) => {
        const gotStream = got.stream(toDownload.browser_download_url)
        // eslint-disable-next-line
        const extractionStream = gotStream.pipe(unzipper.Extract({ path: target }))
        extractionStream.on('close', resolve)
        extractionStream.on('error', reject)
      })
    })
github jie17 / v2ray-electron / download-v2ray.ts View on Github external
function unzipAndMove(params: Params): void {
  fs.createReadStream(params.filename)
    .pipe(Extract({ path: `${process.cwd()}/${params.extractDir}` }))
    .on(
      "finish",
      (): void => {
        fs.renameSync(
          `./${params.extractDir}/config.json`,
          `./${params.extractDir}/config.json.default`
        );
        // Avoid "EPERM: operation not permitted" on Windows
        setTimeout(function(): void {
          fs.renameSync(`./${params.extractDir}`, `./${params.targetDir}`);
        }, 1000);
      }
    );
}
github lifeomic / lambda-tools / src / lambda.js View on Github external
// It would be simpler if the standard TMPDIR directory could be used
  // to extract the zip files, but Docker on Mac is often not configured with
  // access to the Mac's /var temp directory location
  const baseDir = mountpointParent || process.cwd();
  const tempDir = await tmp.dir({ dir: baseDir, mode: '0755', prefix: LAMBDA_TOOLS_WORK_PREFIX });
  const tempDirName = tempDir.path;
  const cleanup = async () => {
    // Delete unzipped files
    await fs.emptyDir(tempDirName);
    await tempDir.cleanup();
  };

  try {
    // eslint-disable-next-line security/detect-non-literal-fs-filename
    const fsStream = fs.createReadStream(zipfile);
    const unzipper = fsStream.pipe(unzip.Extract({
      path: tempDirName
    }));

    await new Promise((resolve, reject) => {
      const endOnError = (error) => reject(error);
      unzipper.on('close', () => resolve());
      fsStream.on('error', endOnError);
      unzipper.on('error', endOnError);
    });

    return {
      mountpoint: tempDirName,
      cleanup
    };
  } catch (e) {
    await cleanup();
github hiddenswitch / Spellsource-Server / launcher / packages / meteor-electron / app / main.js View on Github external
progress(request(url), {throttle: 200}
        ).on('progress', function (state) {
            event.sender.send('file-callback', JSON.stringify({type: 'progress', state: state}));
        }).on('error', (err) => {
            event.sender.send('file-callback', JSON.stringify({type: 'error', error: err}));
        }).on('end', () => {
            try {
                if (!!chmodTarget) {
                    // Make the target executable
                    fs.chmodSync(chmodTarget, '755');
                }
            } catch (e) {
            }
            event.sender.send('file-callback', JSON.stringify({type: 'extracted', extracted: true}));
        }).pipe(unzip.Extract({path: destination}));
    });
github tencentyun / scf-demo-repo / Node8.9_UnzipAndUploadToCOS / index.js View on Github external
})
      fs.writeFileSync(downloadPath, res['Body'])
      console.log('Download file success: ', key)
    } catch (e) {
      console.log(
        `Error getting object ${key} from bucket ${bucket}. Error message: `,
        e
      )
      return 'Fail'
    }

    try {
      const extractPath = path.join(TEMP_PATH, key.substring(0, key.length - 4))
      await fs
        .createReadStream(downloadPath)
        .pipe(unzipper.Extract({ path: extractPath }))
        .promise()

      const files = traversal(extractPath)

      promiseArr = files.map(file => {
        const params = {
          Bucket: `${BUCKET_UPLOAD}-${appId}`,
          Region: REGION,
          Key: file.split('/').pop(),
          Body: fs.readFileSync(file)
        }
        return putObject(params)
      })
    } catch (e) {
      console.log('Unzip file error. Error message:', e)
      return 'Fail'
github mlaursen / react-md / packages / material-icons / createIcons.js View on Github external
async function downloadSource() {
  await fs.remove(temp);
  await fs.ensureDir(temp),
  console.log(`Downloading: '${downloadUrl}'`);
  await download(downloadUrl, temp)

  console.log(`Unzipping to '${path.join(temp, fileName.replace(/\.zip$/, ''))}'...`);
  fs.createReadStream(path.join(temp, fileName))
    .pipe(unzipper.Extract({ path: temp }))
  console.log('Done unzipping!');
}
github fomantic / create-fomantic-icons / lib / tasks / DownloadAsset.js View on Github external
return new Promise(function (resolve) {
        var extractSpinner = Logger_1.spinner()
            .start("extracting asset zip (" + asset.name + ")");
        var assetDirectory = path_1.resolve(os_1.tmpdir(), 'fui-icon-script', asset.name
            .split('.').slice(0, -1).join('.'));
        var assetReadStream = fse.createReadStream(filePath);
        assetReadStream
            .pipe(unzipper_1.Extract({
            path: assetDirectory,
        }));
        assetReadStream
            .once('error', function (err) {
            extractSpinner.stop();
            Logger_1.default.error(err);
            process.exit(1);
        });
        assetReadStream
            .once('close', function () {
            extractSpinner.succeed("asset extracted (" + assetDirectory + ")");
            resolve(assetDirectory);
        });
    });
}
github solvedDev / bridge. / src / renderer / scripts / plugins / PluginLoader.ts View on Github external
static async loadPlugin(project: string, plugin_folder: string, unloaded_plugins: string[]) {
        let plugin_path = path.join(BASE_PATH, project, "bridge/plugins", plugin_folder);
        if((await fs.lstat(plugin_path)).isFile()) {
            if(path.extname(plugin_path) === ".js") {
                //LEGACY PLUGINS
                Store.commit("loadPlugin", {
                    code: (await fs.readFile(plugin_path)).toString(), 
                    path: plugin_path, 
                    blocked: unloaded_plugins.includes(path.basename(plugin_path, ".js"))
                });
            } else if(path.extname(plugin_path) === ".zip") {
                //Load archived plugins
                let unzip_path = path.join(BASE_PATH, project, "bridge/plugins", path.basename(plugin_folder, ".zip"));
                await createReadStream(plugin_path)
                    .pipe(unzipper.Extract({ path: unzip_path }))
                    .promise();
                
                /**
                 * Prevent loading plugin twice
                 * (once as folder and once as .zip)
                 */
                if(PLUGIN_FOLDERS.includes(path.basename(plugin_folder, ".zip"))) {
                    PLUGIN_FOLDERS = PLUGIN_FOLDERS.filter(p => p !== path.basename(plugin_folder, ".zip"));
                }

                await Promise.all([
                    fs.unlink(plugin_path),
                    this.loadPlugin(project, path.basename(plugin_folder, ".zip"), unloaded_plugins)
                ]).catch(e => {});
            }
        } else {
github Robinlim / npm_cache_share / src / js / common / compressUtils.js View on Github external
function zipExtractStream(dir, callback) {
    //错误处理
    function onError(err) {
        throw err;
    }
    //处理结束
    function onClose() {
        callback && callback();
    }
    var extractor = unzipper.Extract({
            path: dir
        })
        .on('error', onError)
        .on('close', onClose);
    return extractor;
}
github onderceylan / puppeteer-demos / whatsapp / functions / index.js View on Github external
return new Promise((resolve, reject) => {
    fs.createReadStream(filePath).pipe(unzipper.Extract({ path: TEMP_USER_FOLDER_PATH })).on('close', resolve).on('error', reject);
  });
}

unzipper

Unzip cross-platform streaming API

MIT
Latest version published 4 months ago

Package Health Score

79 / 100
Full package analysis