UNPKG

tar

Version:
37 lines • 1.53 kB
import { replace, replaceSync } from './replace.js'; // Add a filter that refuses a path that is not newer than the entry // of the same path in the archive. The filter accepts each directory // of the file system: a file in a directory can be newer than the // directory, and the pack reads a directory only if it adds it. // A ustar header has the time in whole seconds. A file is not newer // than such an entry if only the part below one second differs. const isNewer = (file, archived) => { const a = archived.getTime(); const f = file.getTime(); return (a % 1000 === 0 ? f - (f % 1000) : f) > a; }; const newer = (opt) => { const { filter } = opt; const mtimeCache = opt.mtimeCache ?? new Map(); return { ...opt, mtimeCache, filter: (path, entry) => { if (filter && !filter(path, entry)) return false; if ('isDirectory' in entry && entry.isDirectory()) return true; const archived = mtimeCache.get(path); return !archived || !entry.mtime || isNewer(entry.mtime, archived); }, }; }; /** * 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) => replace(newer(opt), files); /** The sync form of `update`. */ export const updateSync = (opt, files) => replaceSync(newer(opt), files); //# sourceMappingURL=update.js.map