UNPKG

tar

Version:
102 lines • 4.75 kB
// The entry point for Node.js, and for each runtime that has the // `node:` modules. It has all that the core entry point has. Each // command gets defaults for the options that the core cannot know: // the file system, the working directory, the platform, the user of // the process, and the codecs of `node:zlib`. It adds the sync // commands. import * as nodeFs from 'node:fs'; import * as nodeFsPromises from 'node:fs/promises'; import { resolve } from 'node:path'; import * as core from '../index.js'; import { createSync as coreCreateSync } from '../create.js'; import { deleteSync as coreDeleteSync } from '../delete.js'; import { dealias, } from '../dealias.js'; import { entriesSync as coreEntriesSync } from '../entries.js'; import { extractSync as coreExtractSync } from '../extract.js'; import { listSync as coreListSync } from '../list.js'; import { replaceSync as coreReplaceSync } from '../replace.js'; import { updateSync as coreUpdateSync } from '../update.js'; import { zlibCodecs } from './codecs.js'; export * from '../index.js'; export { TarReaderSync } from '../entries.js'; export { PackSync } from '../pack.js'; export { ReadEntrySync } from '../read-entry.js'; export { UnpackSync } from '../unpack.js'; export { zlibCodecs, codecStream } from './codecs.js'; const fs = nodeFsPromises; const fsSync = nodeFs; const platform = process.platform === 'win32' ? 'win32' : 'posix'; const codecs = zlibCodecs(); // A copy of the options, with the name of the option in place of // each alias, and a default for each option that is not set. `T` is // the option type of the core command. const fill = (options, fs, paths) => { const opt = dealias(options); opt.fs ??= fs; opt.platform ??= platform; opt.codecs = [...(opt.codecs ?? []), ...codecs]; // A command that reads an archive, and writes no file, does not // need the working directory or the user. if (paths) { // `resolve` adds `process.cwd()` to a relative path. opt.cwd = resolve(opt.cwd ?? ''); opt.processUid ??= process.getuid?.(); opt.processGid ??= process.getgid?.(); opt.processUname ??= process.env.USER; if (opt.chmod) opt.processUmask ??= process.umask(); } return opt; }; /** * Read the entries of an archive. Gzip, brotli, and zstd input is * decompressed, if the runtime has the format. */ export const entries = (input, opt = {}) => core.entries(input, fill(opt, fs, false)); /** The sync form of `entries`. */ export const entriesSync = (input, opt = {}) => coreEntriesSync(input, fill(opt, fsSync, false)); /** * Call `opt.onEntry` with each entry of an archive. If `files` is * set, only with the entries that it lists, and the entries in the * directories that it lists. */ export const list = (opt, files) => core.list(fill(opt, fs, false), files); /** The sync form of `list`. */ export const listSync = (opt, files) => coreListSync(fill(opt, fsSync, false), files); /** * 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. */ export const extract = (opt, files) => core.extract(fill(opt, fs, true), files); /** The sync form of `extract`. */ export const extractSync = (opt, files) => coreExtractSync(fill(opt, fsSync, true), files); export function create(opt, files) { return core.create(fill(opt, fs, true), files); } export function createSync(opt, files) { return coreCreateSync(fill(opt, fsSync, true), files); } /** Add the files to the end of an archive file that is not compressed. */ export const replace = (opt, files) => core.replace(fill(opt, fs, true), files); /** The sync form of `replace`. */ export const replaceSync = (opt, files) => coreReplaceSync(fill(opt, fsSync, true), files); /** * The same as `replace`, but a file is added only if it is newer than * the last entry of the archive that has its path. A directory is * always added, and each path in it is checked. */ export const update = (opt, files) => core.update(fill(opt, fs, true), files); /** The sync form of `update`. */ export const updateSync = (opt, files) => coreUpdateSync(fill(opt, fsSync, true), files); /** * Remove entries from an archive file: each entry that `files` lists, * and each entry in a directory that it lists. With `opt.filter`, * only if the filter also returns true. */ const del = (opt, files) => core.delete(fill(opt, fs, false), files); /** The sync form of `delete`. */ export const deleteSync = (opt, files) => coreDeleteSync(fill(opt, fsSync, false), files); export { del as delete }; export { create as c, extract as x, list as t, replace as r, update as u }; //# sourceMappingURL=index.js.map