Ghost/ghost/zip/lib/extract.js
Hannah Wolfe adfb3fe499 Consistent interface and response
- 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
2020-04-08 12:48:20 +01:00

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};
});
};