How to use the unzipper.Open 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 eclipse-theia / theia / dev-packages / electron / electron-replace-ffmpeg.js View on Github external
encoding: 'utf8'
            }).trim();
        }

        const libffmpegZipPath = await new Promise((resolve, reject) => {
            downloadElectron({
                // `version` usually starts with a `v`, which already gets added by `electron-download`.
                version: electronVersion.replace(/^v/i, ''),
                ffmpeg: true,
            }, (error, path) => {
                if (error) reject(error);
                else resolve(path);
            });
        });

        const libffmpegZip = await unzipper.Open.file(libffmpegZipPath);
        file = libffmpegZip.files.find(file => file.path.endsWith(libffmpegFileName));
        if (!file) {
            throw new Error(`Archive did not contain "${libffmpegFileName}".`);
        }

        // Extract file to cache.
        await new Promise((resolve, reject) => {
            file.stream()
                .pipe(fs.createWriteStream(libffmpegCachedPath))
                .on('finish', resolve)
                .on('error', reject);
        });

        console.info(`Downloaded ffmpeg shared library { version: "${electronVersion}", dist: "${electronDist}" }.`);
    }
github rock-app / fabu.love / server / controllers / upload.js View on Github external
//         .pipe(etl.map(entry => {
            //             // 适配iconPath为ic_launcher.xml的情况
            //             const entryPath = entry.path
            //             // const isXml = entryPath.indexOf('.xml') >= 0
            //             // if ( (!isXml && entryPath.indexOf(iconPath) != -1) || (isXml && entry.path.indexOf(maxSizePath) != -1)) {
            //             //     console.log(entry.path)
            //             entry.pipe(etl.toFile(tempOut))
            //             resolve({ 'success': true, fileName: realPath })
            //             // } else {
            //             //     entry.autodrain()
            //             // }
            //         }))
            // }

            const initialPromise = ext === '.xml' ?
                unzip.Open.file(filepath).then(directory => {
                    const getMaxSizeImagePath = compose(get('path'), maxBy('compressedSize'),
                        filter(entry => entry.path.indexOf(dir) >= 0 && entry.path.indexOf('.png') >= 0), get('files'));
                    maxSizePath = getMaxSizeImagePath(directory)
                }) : new Promise((resolve) => resolve())
            initialPromise.then(() => {
                fs.createReadStream(filepath)
                    .pipe(unzip.Parse())
                    .pipe(etl.map(entry => {
                        // 适配iconPath为ic_launcher.xml的情况
                        const entryPath = entry.path
                        const isXml = entryPath.indexOf('.xml') >= 0
                        if ( (!isXml && entryPath.indexOf(iconPath) != -1) || (isXml && entry.path.indexOf(maxSizePath) != -1)) {
                            console.log(entry.path)
                            entry.pipe(etl.toFile(tempOut))
                            resolve({ 'success': true, fileName: realPath })
                        } else {
github github / vscode-codeql / extensions / ql-vscode / src / distribution.ts View on Github external
export async function extractZipArchive(archivePath: string, outPath: string): Promise {
  const archive = await unzipper.Open.file(archivePath);
  await archive.extract({
    concurrency: 4,
    path: outPath
  });
  // Set file permissions for extracted files
  await Promise.all(archive.files.map(async file => {
    // Only change file permissions if within outPath (path.join normalises the path)
    const extractedPath = path.join(outPath, file.path);
    if (extractedPath.indexOf(outPath) !== 0 || !(await fs.pathExists(extractedPath))) {
      return Promise.resolve();
    }
    return fs.chmod(extractedPath, file.externalFileAttributes >>> 16);
  }));
}
github aws-samples / amazon-rekognition-engagement-meter / src / functions / setup / s3-handler.js View on Github external
copyFiles: () =>
      unzip.Open.s3(s3, { Bucket: FROM_BUCKET, Key: FRONTEND_PATH })
        .then(directory => directory.files.filter(x => x.type !== "Directory"))
        .then(files =>
          files.map(file =>
            upload({
              ACL,
              Body: file.stream(),
              Bucket: TO_BUCKET,
              ContentType: mime.lookup(file.path) || "application/octet-stream",
              Key: file.path
            })
          )
        )
        .then(ps => Promise.all(ps))
        .then(() => console.log("Directory unzipped to S3")),
github AHRQ-CDS / AHRQ-CDS-Connect-Authoring-Tool / api / handlers / externalCQLHandler.js View on Github external
function singlePost(req, res) {
  if (req.user) {
    const { cqlFileName, cqlFileContent, fileType, artifactId } = req.body.library;

    const decodedBuffer = Buffer.from(cqlFileContent, 'base64');

    if (fileType === 'application/zip') {
      unzipper.Open.buffer(decodedBuffer)
        .then(async (directory) => {
          const files = await Promise.all(directory.files.filter(filterCQLFiles).map(async (file) => {
            const buffer = await file.buffer();
            const filePathArray = file.path.split('/');
            const fileName = filePathArray[filePathArray.length - 1];
            return Promise.resolve( { filename: fileName, type: 'text/plain', text: buffer.toString() });
          }));
          makeCQLtoELMRequest(files, [], (err, elmFiles) => {
            if (err) {
              res.status(500).send(err);
              return;
            }

            const { elmErrors, elmResultsToSave } = parseELMFiles(elmFiles, artifactId, req.user.uid, files);

            CQLLibrary.find({ user: req.user.uid, linkedArtifactId: artifactId }, (error, libraries) => {
github aws-samples / amazon-transcribe-news-media-analysis / src / backend / functions / setup / s3-handler.js View on Github external
copyFiles: () =>
        unzip.Open.s3(s3, {Bucket: FROM_BUCKET, Key: FRONTEND_PATH})
            .then(directory => directory.files.filter(x => x.type !== 'Directory'))
            .then(files =>  files.map(
                file => upload({
                    ACL,
                    Body: file.stream(),
                    Bucket: WEBUI_BUCKET,
                    ContentType: mime.lookup(file.path) || 'application/octet-stream',
                    Key: file.path}))
            )
            .then(ps => Promise.all(ps))
            .then(() => console.log('Directory unzipped to S3')),
github getgauge / gauge / build / npm / src / index.js View on Github external
var downloadAndExtract = async function(version) {
    console.log(`Fetching download url for Gauge version ${version}`);
    let url = await install.getBinaryUrl(version);
    let gaugeExecutable = process.platform === "win32" ? "gauge.exe" : "gauge"
    console.log(`Downloading ${url} to ${binPath}`);
    return unzip.Open.url(request, url).then((d) => {
        return new Promise((resolve, reject) => {
            d.files[0].stream()
            .pipe(fs.createWriteStream(path.join(binPath, gaugeExecutable)))
            .on('error',reject)
            .on('finish',resolve)
        });
    });
}
github alanbo / serverless-cms / back_end / functions / mutations / restoreFrombackup.ts View on Github external
async function main() {
    let directory: unzipper.CentralDirectory;

    try {
      directory = await unzipper.Open.s3(s3, {
        Bucket,
        Key: event.id
      });
    } catch (e) {
      callback(e);
    }

    let database_file: unzipper.File;
    let dynamo_delete_finished = false;
    let dynamo_upload_finished = false;
    let s3_upload_finished = false;

    const dynamoStream = db.scan(ddb_params).createReadStream();


    type DynamoStreamChunk = { id: { S: string } }[] | number;
github onigoetz / Comics-Reader / server / books / Zip.js View on Github external
async openFile() {
    return unzipper.Open.file(this.path);
  }

unzipper

Unzip cross-platform streaming API

MIT
Latest version published 10 days ago

Package Health Score

79 / 100
Full package analysis