mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 03:14:03 +03:00
adfb3fe499
- Creating a better, more long-term API here - compress and extract are opposite, neat terms - Use new Promise to get rid of callback argument when using archiver to compress a folder - Add options argument, and make a couple of key details configurable - Make the response intelligable - Ensure both functions are consistent - Updated tests to match
26 lines
856 B
JavaScript
26 lines
856 B
JavaScript
const defaultOptions = {};
|
|
|
|
/**
|
|
* Extract
|
|
*
|
|
* - Unzip an archive to a folder
|
|
*
|
|
* @param {String} zipToExtract - full path to zip file that should be extracted
|
|
* @param {String} destination - full path of the extraction target
|
|
* @param {Object} [options]
|
|
* @param {Integer} options.defaultDirMode - Directory Mode (permissions), defaults to 0o755
|
|
* @param {Integer} options.defaultFileMode - File Mode (permissions), defaults to 0o644
|
|
* @param {Function} options.onEntry - if present, will be called with (entry, zipfile) for every entry in the zip
|
|
*/
|
|
module.exports = (zipToExtract, destination, options) => {
|
|
const opts = Object.assign({}, defaultOptions, options);
|
|
|
|
const extract = require('extract-zip');
|
|
|
|
opts.dir = destination;
|
|
|
|
return extract(zipToExtract, opts).then(() => {
|
|
return {path: destination};
|
|
});
|
|
};
|