diff options
Diffstat (limited to 'desktop/node_modules/extract-zip')
-rw-r--r-- | desktop/node_modules/extract-zip/LICENSE | 23 | ||||
-rwxr-xr-x | desktop/node_modules/extract-zip/cli.js | 19 | ||||
-rw-r--r-- | desktop/node_modules/extract-zip/index.d.ts | 21 | ||||
-rw-r--r-- | desktop/node_modules/extract-zip/index.js | 173 | ||||
-rw-r--r-- | desktop/node_modules/extract-zip/package.json | 80 | ||||
-rw-r--r-- | desktop/node_modules/extract-zip/readme.md | 57 |
6 files changed, 373 insertions, 0 deletions
diff --git a/desktop/node_modules/extract-zip/LICENSE b/desktop/node_modules/extract-zip/LICENSE new file mode 100644 index 0000000..2921069 --- /dev/null +++ b/desktop/node_modules/extract-zip/LICENSE @@ -0,0 +1,23 @@ +Copyright (c) 2014 Max Ogden and other contributors +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/desktop/node_modules/extract-zip/cli.js b/desktop/node_modules/extract-zip/cli.js new file mode 100755 index 0000000..b594016 --- /dev/null +++ b/desktop/node_modules/extract-zip/cli.js @@ -0,0 +1,19 @@ +#!/usr/bin/env node + +/* eslint-disable no-process-exit */ + +var extract = require('./') + +var args = process.argv.slice(2) +var source = args[0] +var dest = args[1] || process.cwd() +if (!source) { + console.error('Usage: extract-zip foo.zip <targetDirectory>') + process.exit(1) +} + +extract(source, { dir: dest }) + .catch(function (err) { + console.error('error!', err) + process.exit(1) + }) diff --git a/desktop/node_modules/extract-zip/index.d.ts b/desktop/node_modules/extract-zip/index.d.ts new file mode 100644 index 0000000..6dbcc80 --- /dev/null +++ b/desktop/node_modules/extract-zip/index.d.ts @@ -0,0 +1,21 @@ +// Based on the type definitions for extract-zip 1.6 +// Definitions by: Mizunashi Mana <https://github.com/mizunashi-mana> +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/e69b58e/types/extract-zip/index.d.ts + +import { Entry, ZipFile } from 'yauzl'; + +declare namespace extract { + interface Options { + dir: string; + defaultDirMode?: number; + defaultFileMode?: number; + onEntry?: (entry: Entry, zipfile: ZipFile) => void; + } +} + +declare function extract( + zipPath: string, + opts: extract.Options, +): Promise<void>; + +export = extract; diff --git a/desktop/node_modules/extract-zip/index.js b/desktop/node_modules/extract-zip/index.js new file mode 100644 index 0000000..23384ea --- /dev/null +++ b/desktop/node_modules/extract-zip/index.js @@ -0,0 +1,173 @@ +const debug = require('debug')('extract-zip') +// eslint-disable-next-line node/no-unsupported-features/node-builtins +const { createWriteStream, promises: fs } = require('fs') +const getStream = require('get-stream') +const path = require('path') +const { promisify } = require('util') +const stream = require('stream') +const yauzl = require('yauzl') + +const openZip = promisify(yauzl.open) +const pipeline = promisify(stream.pipeline) + +class Extractor { + constructor (zipPath, opts) { + this.zipPath = zipPath + this.opts = opts + } + + async extract () { + debug('opening', this.zipPath, 'with opts', this.opts) + + this.zipfile = await openZip(this.zipPath, { lazyEntries: true }) + this.canceled = false + + return new Promise((resolve, reject) => { + this.zipfile.on('error', err => { + this.canceled = true + reject(err) + }) + this.zipfile.readEntry() + + this.zipfile.on('close', () => { + if (!this.canceled) { + debug('zip extraction complete') + resolve() + } + }) + + this.zipfile.on('entry', async entry => { + /* istanbul ignore if */ + if (this.canceled) { + debug('skipping entry', entry.fileName, { cancelled: this.canceled }) + return + } + + debug('zipfile entry', entry.fileName) + + if (entry.fileName.startsWith('__MACOSX/')) { + this.zipfile.readEntry() + return + } + + const destDir = path.dirname(path.join(this.opts.dir, entry.fileName)) + + try { + await fs.mkdir(destDir, { recursive: true }) + + const canonicalDestDir = await fs.realpath(destDir) + const relativeDestDir = path.relative(this.opts.dir, canonicalDestDir) + + if (relativeDestDir.split(path.sep).includes('..')) { + throw new Error(`Out of bound path "${canonicalDestDir}" found while processing file ${entry.fileName}`) + } + + await this.extractEntry(entry) + debug('finished processing', entry.fileName) + this.zipfile.readEntry() + } catch (err) { + this.canceled = true + this.zipfile.close() + reject(err) + } + }) + }) + } + + async extractEntry (entry) { + /* istanbul ignore if */ + if (this.canceled) { + debug('skipping entry extraction', entry.fileName, { cancelled: this.canceled }) + return + } + + if (this.opts.onEntry) { + this.opts.onEntry(entry, this.zipfile) + } + + const dest = path.join(this.opts.dir, entry.fileName) + + // convert external file attr int into a fs stat mode int + const mode = (entry.externalFileAttributes >> 16) & 0xFFFF + // check if it's a symlink or dir (using stat mode constants) + const IFMT = 61440 + const IFDIR = 16384 + const IFLNK = 40960 + const symlink = (mode & IFMT) === IFLNK + let isDir = (mode & IFMT) === IFDIR + + // Failsafe, borrowed from jsZip + if (!isDir && entry.fileName.endsWith('/')) { + isDir = true + } + + // check for windows weird way of specifying a directory + // https://github.com/maxogden/extract-zip/issues/13#issuecomment-154494566 + const madeBy = entry.versionMadeBy >> 8 + if (!isDir) isDir = (madeBy === 0 && entry.externalFileAttributes === 16) + + debug('extracting entry', { filename: entry.fileName, isDir: isDir, isSymlink: symlink }) + + const procMode = this.getExtractedMode(mode, isDir) & 0o777 + + // always ensure folders are created + const destDir = isDir ? dest : path.dirname(dest) + + const mkdirOptions = { recursive: true } + if (isDir) { + mkdirOptions.mode = procMode + } + debug('mkdir', { dir: destDir, ...mkdirOptions }) + await fs.mkdir(destDir, mkdirOptions) + if (isDir) return + + debug('opening read stream', dest) + const readStream = await promisify(this.zipfile.openReadStream.bind(this.zipfile))(entry) + + if (symlink) { + const link = await getStream(readStream) + debug('creating symlink', link, dest) + await fs.symlink(link, dest) + } else { + await pipeline(readStream, createWriteStream(dest, { mode: procMode })) + } + } + + getExtractedMode (entryMode, isDir) { + let mode = entryMode + // Set defaults, if necessary + if (mode === 0) { + if (isDir) { + if (this.opts.defaultDirMode) { + mode = parseInt(this.opts.defaultDirMode, 10) + } + + if (!mode) { + mode = 0o755 + } + } else { + if (this.opts.defaultFileMode) { + mode = parseInt(this.opts.defaultFileMode, 10) + } + + if (!mode) { + mode = 0o644 + } + } + } + + return mode + } +} + +module.exports = async function (zipPath, opts) { + debug('creating target directory', opts.dir) + + if (!path.isAbsolute(opts.dir)) { + throw new Error('Target directory is expected to be absolute') + } + + await fs.mkdir(opts.dir, { recursive: true }) + opts.dir = await fs.realpath(opts.dir) + return new Extractor(zipPath, opts).extract() +} diff --git a/desktop/node_modules/extract-zip/package.json b/desktop/node_modules/extract-zip/package.json new file mode 100644 index 0000000..f59a35a --- /dev/null +++ b/desktop/node_modules/extract-zip/package.json @@ -0,0 +1,80 @@ +{ + "name": "extract-zip", + "version": "2.0.1", + "description": "unzip a zip file into a directory using 100% javascript", + "main": "index.js", + "types": "index.d.ts", + "bin": { + "extract-zip": "cli.js" + }, + "scripts": { + "ava": "ava", + "coverage": "nyc ava", + "lint": "yarn lint:js && yarn lint:ts && yarn tsd", + "lint:js": "eslint .", + "lint:ts": "eslint --config .eslintrc.typescript.js --ext .ts .", + "test": "yarn lint && ava", + "tsd": "tsd" + }, + "files": [ + "cli.js", + "index.d.ts" + ], + "author": "max ogden", + "license": "BSD-2-Clause", + "repository": "maxogden/extract-zip", + "keywords": [ + "unzip", + "zip", + "extract" + ], + "engines": { + "node": ">= 10.17.0" + }, + "dependencies": { + "debug": "^4.1.1", + "get-stream": "^5.1.0", + "yauzl": "^2.10.0" + }, + "optionalDependencies": { + "@types/yauzl": "^2.9.1" + }, + "devDependencies": { + "@typescript-eslint/eslint-plugin": "^3.2.0", + "@typescript-eslint/parser": "^3.2.0", + "ava": "^3.5.1", + "eslint": "^7.2.0", + "eslint-config-standard": "^14.1.1", + "eslint-plugin-ava": "^10.2.0", + "eslint-plugin-import": "^2.20.1", + "eslint-plugin-node": "^11.0.0", + "eslint-plugin-promise": "^4.2.1", + "eslint-plugin-standard": "^4.0.1", + "fs-extra": "^9.0.0", + "husky": "^4.2.3", + "lint-staged": "^10.0.9", + "nyc": "^15.0.0", + "tsd": "^0.11.0", + "typescript": "^3.8.3" + }, + "eslintConfig": { + "extends": [ + "eslint:recommended", + "plugin:ava/recommended", + "plugin:import/errors", + "plugin:import/warnings", + "plugin:node/recommended", + "plugin:promise/recommended", + "standard" + ] + }, + "husky": { + "hooks": { + "pre-commit": "lint-staged" + } + }, + "lint-staged": { + "*.js": "yarn lint:js --fix", + "*.ts": "yarn lint:ts --fix" + } +} diff --git a/desktop/node_modules/extract-zip/readme.md b/desktop/node_modules/extract-zip/readme.md new file mode 100644 index 0000000..4ee7108 --- /dev/null +++ b/desktop/node_modules/extract-zip/readme.md @@ -0,0 +1,57 @@ +# extract-zip + +Unzip written in pure JavaScript. Extracts a zip into a directory. Available as a library or a command line program. + +Uses the [`yauzl`](http://npmjs.org/yauzl) ZIP parser. + +[![NPM](https://nodei.co/npm/extract-zip.png?global=true)](https://npm.im/extract-zip) +[![Uses JS Standard Style](https://cdn.jsdelivr.net/gh/standard/standard/badge.svg)](https://github.com/standard/standard) +[![Build Status](https://github.com/maxogden/extract-zip/workflows/CI/badge.svg)](https://github.com/maxogden/extract-zip/actions?query=workflow%3ACI) + +## Installation + +Make sure you have Node 10 or greater installed. + +Get the library: + +``` +npm install extract-zip --save +``` + +Install the command line program: + +``` +npm install extract-zip -g +``` + +## JS API + +```javascript +const extract = require('extract-zip') + +async function main () { + try { + await extract(source, { dir: target }) + console.log('Extraction complete') + } catch (err) { + // handle any errors + } +} +``` + +### Options + +- `dir` (required) - the path to the directory where the extracted files are written +- `defaultDirMode` - integer - Directory Mode (permissions), defaults to `0o755` +- `defaultFileMode` - integer - File Mode (permissions), defaults to `0o644` +- `onEntry` - function - if present, will be called with `(entry, zipfile)`, entry is every entry from the zip file forwarded from the `entry` event from yauzl. `zipfile` is the `yauzl` instance + +Default modes are only used if no permissions are set in the zip file. + +## CLI Usage + +``` +extract-zip foo.zip <targetDirectory> +``` + +If not specified, `targetDirectory` will default to `process.cwd()`. |