├── .editorconfig ├── .gitattributes ├── .gitignore ├── .npmrc ├── .travis.yml ├── fixtures ├── directory.tar ├── edge_case_dots.tar.gz ├── file.tar ├── file.tar.bz2 ├── file.tar.gz ├── file.zip ├── multiple.zip ├── nested.tar.gz ├── slip.zip ├── slip2.zip ├── slip3.zip ├── slipping.tar.gz ├── slipping_directory.tar.gz ├── strip.tar ├── strip.zip ├── symlink.tar └── top_level_example.tar.gz ├── index.js ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.js text eol=lf 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '13' 4 | - '12' 5 | - '10' 6 | -------------------------------------------------------------------------------- /fixtures/directory.tar: -------------------------------------------------------------------------------- 1 | directory/0000755000076400010400000000000012717622650014477 5ustar vikevmarAdministrators -------------------------------------------------------------------------------- /fixtures/edge_case_dots.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevva/decompress/84a8c1046946add1a6ae01c54dbebf312e4ffc85/fixtures/edge_case_dots.tar.gz -------------------------------------------------------------------------------- /fixtures/file.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevva/decompress/84a8c1046946add1a6ae01c54dbebf312e4ffc85/fixtures/file.tar -------------------------------------------------------------------------------- /fixtures/file.tar.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevva/decompress/84a8c1046946add1a6ae01c54dbebf312e4ffc85/fixtures/file.tar.bz2 -------------------------------------------------------------------------------- /fixtures/file.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevva/decompress/84a8c1046946add1a6ae01c54dbebf312e4ffc85/fixtures/file.tar.gz -------------------------------------------------------------------------------- /fixtures/file.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevva/decompress/84a8c1046946add1a6ae01c54dbebf312e4ffc85/fixtures/file.zip -------------------------------------------------------------------------------- /fixtures/multiple.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevva/decompress/84a8c1046946add1a6ae01c54dbebf312e4ffc85/fixtures/multiple.zip -------------------------------------------------------------------------------- /fixtures/nested.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevva/decompress/84a8c1046946add1a6ae01c54dbebf312e4ffc85/fixtures/nested.tar.gz -------------------------------------------------------------------------------- /fixtures/slip.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevva/decompress/84a8c1046946add1a6ae01c54dbebf312e4ffc85/fixtures/slip.zip -------------------------------------------------------------------------------- /fixtures/slip2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevva/decompress/84a8c1046946add1a6ae01c54dbebf312e4ffc85/fixtures/slip2.zip -------------------------------------------------------------------------------- /fixtures/slip3.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevva/decompress/84a8c1046946add1a6ae01c54dbebf312e4ffc85/fixtures/slip3.zip -------------------------------------------------------------------------------- /fixtures/slipping.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevva/decompress/84a8c1046946add1a6ae01c54dbebf312e4ffc85/fixtures/slipping.tar.gz -------------------------------------------------------------------------------- /fixtures/slipping_directory.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevva/decompress/84a8c1046946add1a6ae01c54dbebf312e4ffc85/fixtures/slipping_directory.tar.gz -------------------------------------------------------------------------------- /fixtures/strip.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevva/decompress/84a8c1046946add1a6ae01c54dbebf312e4ffc85/fixtures/strip.tar -------------------------------------------------------------------------------- /fixtures/strip.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevva/decompress/84a8c1046946add1a6ae01c54dbebf312e4ffc85/fixtures/strip.zip -------------------------------------------------------------------------------- /fixtures/symlink.tar: -------------------------------------------------------------------------------- 1 | test-symlink/symlink0000777000175000017500000000000012641033442016450 2file.txtustar pirannapirannatest-symlink/file.txt0000664000175000017500000000000612641033417015042 0ustar pirannapirannaHello 2 | test-symlink/0000775000175000017500000000000012641033442013364 5ustar pirannapiranna -------------------------------------------------------------------------------- /fixtures/top_level_example.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevva/decompress/84a8c1046946add1a6ae01c54dbebf312e4ffc85/fixtures/top_level_example.tar.gz -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const path = require('path'); 3 | const fs = require('graceful-fs'); 4 | const decompressTar = require('decompress-tar'); 5 | const decompressTarbz2 = require('decompress-tarbz2'); 6 | const decompressTargz = require('decompress-targz'); 7 | const decompressUnzip = require('decompress-unzip'); 8 | const makeDir = require('make-dir'); 9 | const pify = require('pify'); 10 | const stripDirs = require('strip-dirs'); 11 | 12 | const fsP = pify(fs); 13 | 14 | const runPlugins = (input, opts) => { 15 | if (opts.plugins.length === 0) { 16 | return Promise.resolve([]); 17 | } 18 | 19 | return Promise.all(opts.plugins.map(x => x(input, opts))).then(files => files.reduce((a, b) => a.concat(b))); 20 | }; 21 | 22 | const safeMakeDir = (dir, realOutputPath) => { 23 | return fsP.realpath(dir) 24 | .catch(_ => { 25 | const parent = path.dirname(dir); 26 | return safeMakeDir(parent, realOutputPath); 27 | }) 28 | .then(realParentPath => { 29 | if (realParentPath.indexOf(realOutputPath) !== 0) { 30 | throw (new Error('Refusing to create a directory outside the output path.')); 31 | } 32 | 33 | return makeDir(dir).then(fsP.realpath); 34 | }); 35 | }; 36 | 37 | const preventWritingThroughSymlink = (destination, realOutputPath) => { 38 | return fsP.readlink(destination) 39 | .catch(_ => { 40 | // Either no file exists, or it's not a symlink. In either case, this is 41 | // not an escape we need to worry about in this phase. 42 | return null; 43 | }) 44 | .then(symlinkPointsTo => { 45 | if (symlinkPointsTo) { 46 | throw new Error('Refusing to write into a symlink'); 47 | } 48 | 49 | // No symlink exists at `destination`, so we can continue 50 | return realOutputPath; 51 | }); 52 | }; 53 | 54 | const extractFile = (input, output, opts) => runPlugins(input, opts).then(files => { 55 | if (opts.strip > 0) { 56 | files = files 57 | .map(x => { 58 | x.path = stripDirs(x.path, opts.strip); 59 | return x; 60 | }) 61 | .filter(x => x.path !== '.'); 62 | } 63 | 64 | if (typeof opts.filter === 'function') { 65 | files = files.filter(opts.filter); 66 | } 67 | 68 | if (typeof opts.map === 'function') { 69 | files = files.map(opts.map); 70 | } 71 | 72 | if (!output) { 73 | return files; 74 | } 75 | 76 | return Promise.all(files.map(x => { 77 | const dest = path.join(output, x.path); 78 | const mode = x.mode & ~process.umask(); 79 | const now = new Date(); 80 | 81 | if (x.type === 'directory') { 82 | return makeDir(output) 83 | .then(outputPath => fsP.realpath(outputPath)) 84 | .then(realOutputPath => safeMakeDir(dest, realOutputPath)) 85 | .then(() => fsP.utimes(dest, now, x.mtime)) 86 | .then(() => x); 87 | } 88 | 89 | return makeDir(output) 90 | .then(outputPath => fsP.realpath(outputPath)) 91 | .then(realOutputPath => { 92 | // Attempt to ensure parent directory exists (failing if it's outside the output dir) 93 | return safeMakeDir(path.dirname(dest), realOutputPath) 94 | .then(() => realOutputPath); 95 | }) 96 | .then(realOutputPath => { 97 | if (x.type === 'file') { 98 | return preventWritingThroughSymlink(dest, realOutputPath); 99 | } 100 | 101 | return realOutputPath; 102 | }) 103 | .then(realOutputPath => { 104 | return fsP.realpath(path.dirname(dest)) 105 | .then(realDestinationDir => { 106 | if (realDestinationDir.indexOf(realOutputPath) !== 0) { 107 | throw (new Error('Refusing to write outside output directory: ' + realDestinationDir)); 108 | } 109 | }); 110 | }) 111 | .then(() => { 112 | if (x.type === 'link') { 113 | return fsP.link(x.linkname, dest); 114 | } 115 | 116 | if (x.type === 'symlink' && process.platform === 'win32') { 117 | return fsP.link(x.linkname, dest); 118 | } 119 | 120 | if (x.type === 'symlink') { 121 | return fsP.symlink(x.linkname, dest); 122 | } 123 | 124 | return fsP.writeFile(dest, x.data, {mode}); 125 | }) 126 | .then(() => x.type === 'file' && fsP.utimes(dest, now, x.mtime)) 127 | .then(() => x); 128 | })); 129 | }); 130 | 131 | module.exports = (input, output, opts) => { 132 | if (typeof input !== 'string' && !Buffer.isBuffer(input)) { 133 | return Promise.reject(new TypeError('Input file required')); 134 | } 135 | 136 | if (typeof output === 'object') { 137 | opts = output; 138 | output = null; 139 | } 140 | 141 | opts = Object.assign({plugins: [ 142 | decompressTar(), 143 | decompressTarbz2(), 144 | decompressTargz(), 145 | decompressUnzip() 146 | ]}, opts); 147 | 148 | const read = typeof input === 'string' ? fsP.readFile(input) : Promise.resolve(input); 149 | 150 | return read.then(buf => extractFile(buf, output, opts)); 151 | }; 152 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Kevin Mårtensson (github.com/kevva) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "decompress", 3 | "version": "4.2.1", 4 | "description": "Extracting archives made easy", 5 | "license": "MIT", 6 | "repository": "kevva/decompress", 7 | "author": { 8 | "name": "Kevin Mårtensson", 9 | "email": "kevinmartensson@gmail.com", 10 | "url": "github.com/kevva" 11 | }, 12 | "engines": { 13 | "node": ">=4" 14 | }, 15 | "scripts": { 16 | "test": "xo && ava" 17 | }, 18 | "files": [ 19 | "index.js" 20 | ], 21 | "keywords": [ 22 | "bz2", 23 | "bzip2", 24 | "decompress", 25 | "extract", 26 | "tar", 27 | "tar.bz", 28 | "tar.gz", 29 | "zip", 30 | "unzip" 31 | ], 32 | "dependencies": { 33 | "decompress-tar": "^4.0.0", 34 | "decompress-tarbz2": "^4.0.0", 35 | "decompress-targz": "^4.0.0", 36 | "decompress-unzip": "^4.0.1", 37 | "graceful-fs": "^4.1.10", 38 | "make-dir": "^1.0.0", 39 | "pify": "^2.3.0", 40 | "strip-dirs": "^2.0.0" 41 | }, 42 | "devDependencies": { 43 | "ava": "*", 44 | "esm": "^3.2.25", 45 | "is-jpg": "^1.0.0", 46 | "path-exists": "^3.0.0", 47 | "pify": "^2.3.0", 48 | "rimraf": "^3.0.2", 49 | "xo": "*" 50 | }, 51 | "ava": { 52 | "require": [ 53 | "esm" 54 | ] 55 | }, 56 | "xo": { 57 | "rules": { 58 | "promise/prefer-await-to-then": "off" 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # decompress [![Build Status](https://travis-ci.org/kevva/decompress.svg?branch=master)](https://travis-ci.org/kevva/decompress) 2 | 3 | > Extracting archives made easy 4 | 5 | *See [decompress-cli](https://github.com/kevva/decompress-cli) for the command-line version.* 6 | 7 | ## Install 8 | 9 | ``` 10 | $ npm install decompress 11 | ``` 12 | 13 | 14 | ## Usage 15 | 16 | ```js 17 | const decompress = require('decompress'); 18 | 19 | decompress('unicorn.zip', 'dist').then(files => { 20 | console.log('done!'); 21 | }); 22 | ``` 23 | 24 | 25 | ## API 26 | 27 | ### decompress(input, [output], [options]) 28 | 29 | Returns a Promise for an array of files in the following format: 30 | 31 | ```js 32 | { 33 | data: Buffer, 34 | mode: Number, 35 | mtime: String, 36 | path: String, 37 | type: String 38 | } 39 | ``` 40 | 41 | #### input 42 | 43 | Type: `string` `Buffer` 44 | 45 | File to decompress. 46 | 47 | #### output 48 | 49 | Type: `string` 50 | 51 | Output directory. 52 | 53 | #### options 54 | 55 | ##### filter 56 | 57 | Type: `Function` 58 | 59 | Filter out files before extracting. E.g: 60 | 61 | ```js 62 | decompress('unicorn.zip', 'dist', { 63 | filter: file => path.extname(file.path) !== '.exe' 64 | }).then(files => { 65 | console.log('done!'); 66 | }); 67 | ``` 68 | 69 | *Note that in the current implementation, **`filter` is only applied after fully reading all files from the archive in memory**. Do not rely on this option to limit the amount of memory used by `decompress` to the size of the files included by `filter`. `decompress` will read the entire compressed file into memory regardless.* 70 | 71 | ##### map 72 | 73 | Type: `Function` 74 | 75 | Map files before extracting: E.g: 76 | 77 | ```js 78 | decompress('unicorn.zip', 'dist', { 79 | map: file => { 80 | file.path = `unicorn-${file.path}`; 81 | return file; 82 | } 83 | }).then(files => { 84 | console.log('done!'); 85 | }); 86 | ``` 87 | 88 | ##### plugins 89 | 90 | Type: `Array`
91 | Default: `[decompressTar(), decompressTarbz2(), decompressTargz(), decompressUnzip()]` 92 | 93 | Array of [plugins](https://www.npmjs.com/browse/keyword/decompressplugin) to use. 94 | 95 | ##### strip 96 | 97 | Type: `number`
98 | Default: `0` 99 | 100 | Remove leading directory components from extracted files. 101 | 102 | 103 | ## License 104 | 105 | MIT © [Kevin Mårtensson](https://github.com/kevva) 106 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import path from 'path'; 3 | import isJpg from 'is-jpg'; 4 | import pathExists from 'path-exists'; 5 | import pify from 'pify'; 6 | import rimraf from 'rimraf'; 7 | import test from 'ava'; 8 | import m from '.'; 9 | 10 | const fsP = pify(fs); 11 | const rimrafP = pify(rimraf); 12 | 13 | test.serial.afterEach('ensure decompressed files and directories are cleaned up', async () => { 14 | await rimrafP(path.join(__dirname, 'directory')); 15 | await rimrafP(path.join(__dirname, 'dist')); 16 | await rimrafP(path.join(__dirname, 'example.txt')); 17 | await rimrafP(path.join(__dirname, 'file.txt')); 18 | await rimrafP(path.join(__dirname, 'edge_case_dots')); 19 | await rimrafP(path.join(__dirname, 'symlink')); 20 | await rimrafP(path.join(__dirname, 'test.jpg')); 21 | }); 22 | 23 | test('extract file', async t => { 24 | const tarFiles = await m(path.join(__dirname, 'fixtures', 'file.tar')); 25 | const tarbzFiles = await m(path.join(__dirname, 'fixtures', 'file.tar.bz2')); 26 | const targzFiles = await m(path.join(__dirname, 'fixtures', 'file.tar.gz')); 27 | const zipFiles = await m(path.join(__dirname, 'fixtures', 'file.zip')); 28 | 29 | t.is(tarFiles[0].path, 'test.jpg'); 30 | t.true(isJpg(tarFiles[0].data)); 31 | t.is(tarbzFiles[0].path, 'test.jpg'); 32 | t.true(isJpg(tarbzFiles[0].data)); 33 | t.is(targzFiles[0].path, 'test.jpg'); 34 | t.true(isJpg(targzFiles[0].data)); 35 | t.is(zipFiles[0].path, 'test.jpg'); 36 | t.true(isJpg(zipFiles[0].data)); 37 | }); 38 | 39 | test('extract file using buffer', async t => { 40 | const tarBuf = await fsP.readFile(path.join(__dirname, 'fixtures', 'file.tar')); 41 | const tarFiles = await m(tarBuf); 42 | const tarbzBuf = await fsP.readFile(path.join(__dirname, 'fixtures', 'file.tar.bz2')); 43 | const tarbzFiles = await m(tarbzBuf); 44 | const targzBuf = await fsP.readFile(path.join(__dirname, 'fixtures', 'file.tar.gz')); 45 | const targzFiles = await m(targzBuf); 46 | const zipBuf = await fsP.readFile(path.join(__dirname, 'fixtures', 'file.zip')); 47 | const zipFiles = await m(zipBuf); 48 | 49 | t.is(tarFiles[0].path, 'test.jpg'); 50 | t.is(tarbzFiles[0].path, 'test.jpg'); 51 | t.is(targzFiles[0].path, 'test.jpg'); 52 | t.is(zipFiles[0].path, 'test.jpg'); 53 | }); 54 | 55 | test.serial('extract file to directory', async t => { 56 | const files = await m(path.join(__dirname, 'fixtures', 'file.tar'), __dirname); 57 | 58 | t.is(files[0].path, 'test.jpg'); 59 | t.true(isJpg(files[0].data)); 60 | t.true(await pathExists(path.join(__dirname, 'test.jpg'))); 61 | }); 62 | 63 | test.serial('extract symlink', async t => { 64 | await m(path.join(__dirname, 'fixtures', 'symlink.tar'), __dirname, {strip: 1}); 65 | t.is(await fsP.realpath(path.join(__dirname, 'symlink')), path.join(__dirname, 'file.txt')); 66 | }); 67 | 68 | test.serial('extract directory', async t => { 69 | await m(path.join(__dirname, 'fixtures', 'directory.tar'), __dirname); 70 | t.true(await pathExists(path.join(__dirname, 'directory'))); 71 | }); 72 | 73 | test('strip option', async t => { 74 | const zipFiles = await m(path.join(__dirname, 'fixtures', 'strip.zip'), {strip: 1}); 75 | const tarFiles = await m(path.join(__dirname, 'fixtures', 'strip.tar'), {strip: 1}); 76 | 77 | t.is(zipFiles[0].path, 'test-strip.jpg'); 78 | t.true(isJpg(zipFiles[0].data)); 79 | t.is(tarFiles[0].path, 'test-strip.jpg'); 80 | t.true(isJpg(tarFiles[0].data)); 81 | }); 82 | 83 | test('filter option', async t => { 84 | const files = await m(path.join(__dirname, 'fixtures', 'file.tar'), { 85 | filter: x => x.path !== 'test.jpg' 86 | }); 87 | 88 | t.is(files.length, 0); 89 | }); 90 | 91 | test('map option', async t => { 92 | const files = await m(path.join(__dirname, 'fixtures', 'file.tar'), { 93 | map: x => { 94 | x.path = `unicorn-${x.path}`; 95 | return x; 96 | } 97 | }); 98 | 99 | t.is(files[0].path, 'unicorn-test.jpg'); 100 | }); 101 | 102 | test.serial('set mtime', async t => { 103 | const files = await m(path.join(__dirname, 'fixtures', 'file.tar'), __dirname); 104 | const stat = await fsP.stat(path.join(__dirname, 'test.jpg')); 105 | t.deepEqual(files[0].mtime, stat.mtime); 106 | }); 107 | 108 | test('return emptpy array if no plugins are set', async t => { 109 | const files = await m(path.join(__dirname, 'fixtures', 'file.tar'), {plugins: []}); 110 | t.is(files.length, 0); 111 | }); 112 | 113 | test.serial('throw when a location outside the root is given', async t => { 114 | await t.throwsAsync(async () => { 115 | await m(path.join(__dirname, 'fixtures', 'slipping.tar.gz'), 'dist'); 116 | }, {message: /Refusing/}); 117 | }); 118 | 119 | test.serial('throw when a location outside the root including symlinks is given', async t => { 120 | await t.throwsAsync(async () => { 121 | await m(path.join(__dirname, 'fixtures', 'slip.zip'), 'dist'); 122 | }, {message: /Refusing/}); 123 | }); 124 | 125 | test.serial('throw when a top-level symlink outside the root is given', async t => { 126 | await t.throwsAsync(async () => { 127 | await m(path.join(__dirname, 'fixtures', 'slip2.zip'), 'dist'); 128 | }, {message: /Refusing/}); 129 | }); 130 | 131 | test.serial('throw when a directory outside the root including symlinks is given', async t => { 132 | await t.throwsAsync(async () => { 133 | await m(path.join(__dirname, 'fixtures', 'slipping_directory.tar.gz'), 'dist'); 134 | }, {message: /Refusing/}); 135 | }); 136 | 137 | test.serial('allows filenames and directories to be written with dots in their names', async t => { 138 | const files = await m(path.join(__dirname, 'fixtures', 'edge_case_dots.tar.gz'), __dirname); 139 | t.is(files.length, 6); 140 | t.deepEqual(files.map(f => f.path).sort(), [ 141 | 'edge_case_dots/', 142 | 'edge_case_dots/internal_dots..txt', 143 | 'edge_case_dots/sample../', 144 | 'edge_case_dots/ending_dots..', 145 | 'edge_case_dots/x', 146 | 'edge_case_dots/sample../test.txt' 147 | ].sort()); 148 | }); 149 | 150 | test.serial('allows top-level file', async t => { 151 | const files = await m(path.join(__dirname, 'fixtures', 'top_level_example.tar.gz'), 'dist'); 152 | t.is(files.length, 1); 153 | t.is(files[0].path, 'example.txt'); 154 | }); 155 | 156 | test.serial('throw when chained symlinks to /tmp/dist allow escape outside root directory', async t => { 157 | await t.throwsAsync(async () => { 158 | await m(path.join(__dirname, 'fixtures', 'slip3.zip'), '/tmp/dist'); 159 | }, {message: /Refusing/}); 160 | }); 161 | --------------------------------------------------------------------------------