How to use adm-zip - 10 common examples

To help you get started, we’ve selected a few adm-zip 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 aws-samples / cloudfront-authorization-at-edge / src / cfn-custom-resources / lambda-code-update / index.ts View on Github external
async function updateLambdaCode(action: 'Create' | 'Update' | 'Delete', lambdaFunction: string, configuration: string, physicalResourceId?: string) {
    if (action === 'Delete') {
        // Deletes aren't executed; the Lambda Resource should just be deleted
        return { physicalResourceId: physicalResourceId!, Data: {} };
    }
    console.log(`Adding configuration to Lambda function ${lambdaFunction}:\n${configuration}`);
    const { Code } = await LAMBDA_CLIENT.getFunction({ FunctionName: lambdaFunction }).promise();
    const { data } = await axios.get(Code!.Location!, { responseType: 'arraybuffer' });

    // Extract Lambda zip contents to temporary folder, add configuration.json, and rezip
    const lambdaZip = new Zip(data);
    console.log('Lambda zip contents:', lambdaZip.getEntries().map(entry => entry.name));
    console.log('Adding (fresh) configuration.json ...');
    const tempDir = mkdtempSync('/tmp/lambda-package');
    lambdaZip.extractAllTo(tempDir, true);
    writeFileSync(resolve(tempDir, 'configuration.json'), Buffer.from(configuration));
    const newLambdaZip = new Zip();
    newLambdaZip.addLocalFolder(tempDir);
    console.log('New Lambda zip contents:', newLambdaZip.getEntries().map(entry => entry.name));
    
    const { CodeSha256, Version, FunctionArn } = await LAMBDA_CLIENT.updateFunctionCode(
        {
            FunctionName: lambdaFunction,
            ZipFile: newLambdaZip.toBuffer(),
            Publish: true
        }
    ).promise();
github lin-xi / mark / src / services / data.js View on Github external
}, (filePaths, bookmark) => {
          if (filePaths.length == 0) return

          let zip = new AdmZip(filePaths[0])
          var zipEntries = zip.getEntries()

          zipEntries.forEach(function (zipEntry) {
            // console.log(zipEntry.entryName)
            if (zipEntry.entryName == 'plan.db' || zipEntry.entryName == 'note.db') {
              // console.log(zipEntry.getData().toString('utf8'))
              fs.writeFileSync(global.dataPath + '/' + zipEntry.entryName, zipEntry.getData().toString('utf8'), 'utf8')
            }
          })

          dialog.showMessageBox(global.win, {
            type: 'info',
            title: 'Mark',
            message: '导入数据成功'
          })
        })
github facebookarchive / flow-language-server / src / flow-versions / githubSemverDownloader.js View on Github external
}

  reporter.info(
    `Found a match with version ${bestMatch.tag_name} on GitHub. Downloading...`,
  );

  const archiveResponse = await fetch(url);
  if (archiveResponse.ok) {
    const zipBuffer = await archiveResponse.buffer();
    // $FlowFixMe https://github.com/flowtype/flow-typed/pull/1049
    const version = (semver.clean(bestMatch.tag_name): string);
    const destDir = path.join(binsDir, version);

    try {
      await mkdirp(destDir);
      new Zip(zipBuffer).extractEntryTo(
        path.join('flow', 'flow'),
        destDir,
        false /* don't recreate the entry 'flow' dir */,
        true /* overwrite */,
      );
    } catch (e) {
      reporter.error(
        'Failed to write flow binary to disk. Please ensure write access ' +
          `to ${destDir}.`,
      );
      return null;
    }

    reporter.info(
      `Successfully downloaded and installed flow version ${bestMatch.tag_name} from GitHub`,
    );
github vpdb / server / src / app / files / metadata / archive.metadata.ts View on Github external
private getZipMetadata(path: string) {
		try {

			let entries = new Zip(path).getEntries();

			// filter directories
			entries = entries.filter(entry => !entry.isDirectory);

			// map data to something useful
			return {
				entries: entries.map((entry: any) => {
					return {
						filename: entry.entryName,
						bytes: entry.header.size,
						bytes_compressed: entry.header.compressedSize,
						crc: entry.header.crc,
						modified_at: new Date(entry.header.time),
					};
				}),
			};
github appcelerator / node-appc / lib / zip.js View on Github external
(function extractFile() {
			if (i < len) {
				try {
					const entry = zipEntries[i];

					if (visitor(entry, i, len) !== false) {
						if (entry.isDirectory) {
							Utils.makeDir(afs.resolvePath(dest, entry.entryName.toString()));
						} else {
							const content = entry.getData();
							if (!content) {
								// FIXME: This is clearly wrong, but not sure if downstream depends on this behavior!
								throw Utils.Errors.CANT_EXTRACT_FILE + '2'; // eslint-disable-line no-throw-literal
							}
							Utils.writeFileTo(
								afs.resolvePath(dest, entry.entryName.toString()),
								content,
								overwrite,
								(entry.header.attr && (entry.header.attr >>> 16) || defaultPerm) & 0o777
							);
						}
					}

					i++;
					setTimeout(extractFile, 0);
				} catch (ex) {
					finished(ex, i, len);
				}
			} else {
github appcelerator / node-appc / lib / zip.js View on Github external
(function extractFile() {
			if (i < len) {
				try {
					const entry = zipEntries[i];

					if (visitor(entry, i, len) !== false) {
						if (entry.isDirectory) {
							Utils.makeDir(afs.resolvePath(dest, entry.entryName.toString()));
						} else {
							const content = entry.getData();
							if (!content) {
								// FIXME: This is clearly wrong, but not sure if downstream depends on this behavior!
								throw Utils.Errors.CANT_EXTRACT_FILE + '2'; // eslint-disable-line no-throw-literal
							}
							Utils.writeFileTo(
								afs.resolvePath(dest, entry.entryName.toString()),
								content,
								overwrite,
								(entry.header.attr && (entry.header.attr >>> 16) || defaultPerm) & 0o777
							);
						}
					}

					i++;
github appcelerator / node-appc / lib / zip.js View on Github external
(function extractFile() {
			if (i < len) {
				try {
					const entry = zipEntries[i];

					if (visitor(entry, i, len) !== false) {
						if (entry.isDirectory) {
							Utils.makeDir(afs.resolvePath(dest, entry.entryName.toString()));
						} else {
							const content = entry.getData();
							if (!content) {
								// FIXME: This is clearly wrong, but not sure if downstream depends on this behavior!
								throw Utils.Errors.CANT_EXTRACT_FILE + '2'; // eslint-disable-line no-throw-literal
							}
							Utils.writeFileTo(
								afs.resolvePath(dest, entry.entryName.toString()),
								content,
								overwrite,
								(entry.header.attr && (entry.header.attr >>> 16) || defaultPerm) & 0o777
							);
						}
					}

					i++;
					setTimeout(extractFile, 0);
				} catch (ex) {
					finished(ex, i, len);
				}
			} else {
				// done!
				finished(null, i, len);
github unfoldingWord / translationCore / src / js / helpers / ResourcesHelpers.js View on Github external
export const extractZippedResourceContent = (resourceDestinationPath, isBible) => {
  const versions = ResourceAPI.listVersions(resourceDestinationPath);

  for (const version of versions) {
    const versionPath = path.join(resourceDestinationPath, version);
    const filename = isBible ? 'books.zip' : 'contents.zip';
    const contentZipPath = path.join(versionPath, filename);

    if (fs.existsSync(contentZipPath)) {
      console.log(`extractZippedResourceContent: unzipping ${contentZipPath}`);
      const zip = new AdmZip(contentZipPath);
      zip.extractAllTo(versionPath, /*overwrite*/true);

      if (fs.existsSync(contentZipPath)) {
        fs.removeSync(contentZipPath);
      }
    } else {
      console.warn(`extractZippedResourceContent: ${contentZipPath}, Path Does not exist`);
    }
  }
};
github simonknittel / discord-bot-api / updater / index.js View on Github external
function unzipLatest(callback) {
    let zip = new AdmZip('./latest.zip');
    zip.extractAllTo('./latest/', true);
    callback();
}
github imlucas / lone / embed / admzip.js View on Github external
return compressedData;
                }
                var data = new Buffer(_entryHeader.size);
                data.fill(0);
                switch (_entryHeader.method) {
                  case Utils.Constants.STORED:
                    compressedData.copy(data);
                    if (!crc32OK(data)) {
                        if (async && callback) callback(data, Utils.Errors.BAD_CRC);
                        return Utils.Errors.BAD_CRC;
                    } else {
                        if (async && callback) callback(data);
                        return data;
                    }
                    break;
                  case Utils.Constants.DEFLATED:
                    var inflater = new Methods.Inflater(compressedData);
                    if (!async) {
                        inflater.inflate(data);
                        if (!crc32OK(data)) {
                            console.warn(Utils.Errors.BAD_CRC + " " + _entryName.toString());
                        }
                        return data;
                    } else {
                        inflater.inflateAsync(function(result) {
                            result.copy(data, 0);
                            if (crc32OK(data)) {
                                if (callback) callback(data, Utils.Errors.BAD_CRC);
                            } else {
                                if (callback) callback(data);
                            }
                        });