aboutsummaryrefslogtreecommitdiffstats
path: root/node_modules/tar/dist/esm/list.js
diff options
context:
space:
mode:
authorpack <pack@packgekko.xyz>2026-08-09 10:37:07 +0000
committerpack <pack@packgekko.xyz>2026-08-09 10:37:07 +0000
commit55a4f1fc869e41aca748c63d3018f0448b1606e0 (patch)
treed132d1d01772b6d53faee3e63c534dea5706b78a /node_modules/tar/dist/esm/list.js
downloadcrud-55a4f1fc869e41aca748c63d3018f0448b1606e0.tar.gz
first commit
Diffstat (limited to 'node_modules/tar/dist/esm/list.js')
-rw-r--r--node_modules/tar/dist/esm/list.js113
1 files changed, 113 insertions, 0 deletions
diff --git a/node_modules/tar/dist/esm/list.js b/node_modules/tar/dist/esm/list.js
new file mode 100644
index 0000000..08bdbe4
--- /dev/null
+++ b/node_modules/tar/dist/esm/list.js
@@ -0,0 +1,113 @@
+// tar -t
+import * as fsm from '@isaacs/fs-minipass';
+import fs from 'node:fs';
+import { dirname, parse } from 'path';
+import { makeCommand } from './make-command.js';
+import { Parser } from './parse.js';
+import { stripTrailingSlashes } from './strip-trailing-slashes.js';
+const onReadEntryFunction = (opt) => {
+ const onReadEntry = opt.onReadEntry;
+ opt.onReadEntry =
+ onReadEntry ?
+ e => {
+ onReadEntry(e);
+ e.resume();
+ }
+ : e => e.resume();
+};
+// construct a filter that limits the file entries listed
+// include child entries if a dir is included
+export const filesFilter = (opt, files) => {
+ const map = new Map(files.map(f => [stripTrailingSlashes(f), true]));
+ const filter = opt.filter;
+ // limit recursion to 100 levels
+ const MAX = 100;
+ const mapHas = (file, r = '', depth = 0) => {
+ /* c8 ignore start - excessive caution */
+ if (depth >= MAX) {
+ map.set(file, false);
+ return false;
+ }
+ /* c8 ignore stop */
+ const root = r || parse(file).root || '.';
+ let ret;
+ if (file === root)
+ ret = false;
+ else {
+ const m = map.get(file);
+ ret = m !== undefined ? m : mapHas(dirname(file), root, depth + 1);
+ }
+ map.set(file, ret);
+ return ret;
+ };
+ opt.filter =
+ filter ?
+ (file, entry) => filter(file, entry) && mapHas(stripTrailingSlashes(file))
+ : file => mapHas(stripTrailingSlashes(file));
+};
+const listFileSync = (opt) => {
+ const p = new Parser(opt);
+ const file = opt.file;
+ let fd;
+ try {
+ fd = fs.openSync(file, 'r');
+ const stat = fs.fstatSync(fd);
+ const readSize = opt.maxReadSize || 16 * 1024 * 1024;
+ if (stat.size < readSize) {
+ const buf = Buffer.allocUnsafe(stat.size);
+ const read = fs.readSync(fd, buf, 0, stat.size, 0);
+ p.end(read === buf.byteLength ? buf : buf.subarray(0, read));
+ }
+ else {
+ let pos = 0;
+ const buf = Buffer.allocUnsafe(readSize);
+ while (pos < stat.size) {
+ const bytesRead = fs.readSync(fd, buf, 0, readSize, pos);
+ if (bytesRead === 0)
+ break;
+ pos += bytesRead;
+ p.write(buf.subarray(0, bytesRead));
+ }
+ p.end();
+ }
+ }
+ finally {
+ if (typeof fd === 'number') {
+ try {
+ fs.closeSync(fd);
+ /* c8 ignore next */
+ }
+ catch { }
+ }
+ }
+};
+const listFile = (opt, _files) => {
+ const parse = new Parser(opt);
+ const readSize = opt.maxReadSize || 16 * 1024 * 1024;
+ const file = opt.file;
+ const p = new Promise((resolve, reject) => {
+ parse.on('error', reject);
+ parse.on('end', resolve);
+ fs.stat(file, (er, stat) => {
+ if (er) {
+ reject(er);
+ }
+ else {
+ const stream = new fsm.ReadStream(file, {
+ readSize: readSize,
+ size: stat.size,
+ });
+ stream.on('error', reject);
+ stream.pipe(parse);
+ }
+ });
+ });
+ return p;
+};
+export const list = makeCommand(listFileSync, listFile, opt => new Parser(opt), opt => new Parser(opt), (opt, files) => {
+ if (files?.length)
+ filesFilter(opt, files);
+ if (!opt.noResume)
+ onReadEntryFunction(opt);
+});
+//# sourceMappingURL=list.js.map \ No newline at end of file