tar
Version:
tar for JavaScript
47 lines • 1.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractSync = exports.extract = void 0;
const dealias_js_1 = require("./dealias.js");
const list_js_1 = require("./list.js");
const read_file_js_1 = require("./read-file.js");
const unpack_js_1 = require("./unpack.js");
const noInput = () => new TypeError('extract needs input or file');
/**
* Extract the entries of an archive into the directory `opt.cwd`.
* If `files` is set, only the entries that it lists, and the entries
* in the directories that it lists.
*
* A problem with one entry is a warning for `opt.onwarn`, and the
* extraction continues. A listed path that no entry matches is a
* warning when the archive ends. With `opt.strict`, each is an error.
*/
const extract = async (options, files) => {
const opt = (0, dealias_js_1.dealias)(options);
const source = opt.input ??
(opt.file ? (0, read_file_js_1.readFile)(opt.fs, opt.file, opt.maxReadSize) : undefined);
if (!source)
throw noInput();
const [filter, report] = files?.length ? (0, list_js_1.filesFilter)(files, opt.filter) : [];
if (filter)
opt.filter = filter;
await new unpack_js_1.Unpack(opt).extract(source);
report?.(opt);
};
exports.extract = extract;
/** The sync form of `extract`. */
const extractSync = (options, files) => {
const opt = (0, dealias_js_1.dealias)(options);
const source = opt.input ??
(opt.file ?
(0, read_file_js_1.readFileSync)(opt.fs, opt.file, opt.maxReadSize)
: undefined);
if (!source)
throw noInput();
const [filter, report] = files?.length ? (0, list_js_1.filesFilter)(files, opt.filter) : [];
if (filter)
opt.filter = filter;
new unpack_js_1.UnpackSync(opt).extract(source);
report?.(opt);
};
exports.extractSync = extractSync;
//# sourceMappingURL=extract.js.map