Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
extract.js88 linesDownload Raw Back to commonjs
1"use strict";
2var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3    if (k2 === undefined) k2 = k;
4    var desc = Object.getOwnPropertyDescriptor(m, k);
5    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6      desc = { enumerable: true, get: function() { return m[k]; } };
7    }
8    Object.defineProperty(o, k2, desc);
9}) : (function(o, m, k, k2) {
10    if (k2 === undefined) k2 = k;
11    o[k2] = m[k];
12}));
13var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14    Object.defineProperty(o, "default", { enumerable: true, value: v });
15}) : function(o, v) {
16    o["default"] = v;
17});
18var __importStar = (this && this.__importStar) || (function () {
19    var ownKeys = function(o) {
20        ownKeys = Object.getOwnPropertyNames || function (o) {
21            var ar = [];
22            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23            return ar;
24        };
25        return ownKeys(o);
26    };
27    return function (mod) {
28        if (mod && mod.__esModule) return mod;
29        var result = {};
30        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31        __setModuleDefault(result, mod);
32        return result;
33    };
34})();
35var __importDefault = (this && this.__importDefault) || function (mod) {
36    return (mod && mod.__esModule) ? mod : { "default": mod };
37};
38Object.defineProperty(exports, "__esModule", { value: true });
39exports.extract = void 0;
40// tar -x
41const fsm = __importStar(require("@isaacs/fs-minipass"));
42const node_fs_1 = __importDefault(require("node:fs"));
43const list_js_1 = require("./list.js");
44const make_command_js_1 = require("./make-command.js");
45const unpack_js_1 = require("./unpack.js");
46const extractFileSync = (opt) => {
47    const u = new unpack_js_1.UnpackSync(opt);
48    const file = opt.file;
49    const stat = node_fs_1.default.statSync(file);
50    // This trades a zero-byte read() syscall for a stat
51    // However, it will usually result in less memory allocation
52    const readSize = opt.maxReadSize || 16 * 1024 * 1024;
53    const stream = new fsm.ReadStreamSync(file, {
54        readSize: readSize,
55        size: stat.size,
56    });
57    stream.pipe(u);
58};
59const extractFile = (opt, _) => {
60    const u = new unpack_js_1.Unpack(opt);
61    const readSize = opt.maxReadSize || 16 * 1024 * 1024;
62    const file = opt.file;
63    const p = new Promise((resolve, reject) => {
64        u.on('error', reject);
65        u.on('close', resolve);
66        // This trades a zero-byte read() syscall for a stat
67        // However, it will usually result in less memory allocation
68        node_fs_1.default.stat(file, (er, stat) => {
69            if (er) {
70                reject(er);
71            }
72            else {
73                const stream = new fsm.ReadStream(file, {
74                    readSize: readSize,
75                    size: stat.size,
76                });
77                stream.on('error', reject);
78                stream.pipe(u);
79            }
80        });
81    });
82    return p;
83};
84exports.extract = (0, make_command_js_1.makeCommand)(extractFileSync, extractFile, opt => new unpack_js_1.UnpackSync(opt), opt => new unpack_js_1.Unpack(opt), (opt, files) => {
85    if (files?.length)
86        (0, list_js_1.filesFilter)(opt, files);
87});
88//# sourceMappingURL=extract.js.map
codekingpro/portable-devtools · Team Ai