basant307/AI_Governance_Project
048
1"use strict";2var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {3 if (k2 === undefined) k2 = k;4 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });5}) : (function(o, m, k, k2) {6 if (k2 === undefined) k2 = k;7 o[k2] = m[k];8}));9var __exportStar = (this && this.__exportStar) || function(m, exports) {10 for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);11};12var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {13 if (kind === "m") throw new TypeError("Private method is not writable");14 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");15 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");16 return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;17};18var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {19 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");20 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");21 return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);22};23var __importDefault = (this && this.__importDefault) || function (mod) {24 return (mod && mod.__esModule) ? mod : { "default": mod };25};26var _FileFromPath_path, _FileFromPath_start;27Object.defineProperty(exports, "__esModule", { value: true });28exports.fileFromPath = exports.fileFromPathSync = void 0;29const fs_1 = require("fs");30const path_1 = require("path");31const node_domexception_1 = __importDefault(require("node-domexception"));32const File_1 = require("./File");33const isPlainObject_1 = __importDefault(require("./isPlainObject"));34__exportStar(require("./isFile"), exports);35const MESSAGE = "The requested file could not be read, "36 + "typically due to permission problems that have occurred after a reference "37 + "to a file was acquired.";38class FileFromPath {39 constructor(input) {40 _FileFromPath_path.set(this, void 0);41 _FileFromPath_start.set(this, void 0);42 __classPrivateFieldSet(this, _FileFromPath_path, input.path, "f");43 __classPrivateFieldSet(this, _FileFromPath_start, input.start || 0, "f");44 this.name = (0, path_1.basename)(__classPrivateFieldGet(this, _FileFromPath_path, "f"));45 this.size = input.size;46 this.lastModified = input.lastModified;47 }48 slice(start, end) {49 return new FileFromPath({50 path: __classPrivateFieldGet(this, _FileFromPath_path, "f"),51 lastModified: this.lastModified,52 size: end - start,53 start54 });55 }56 async *stream() {57 const { mtimeMs } = await fs_1.promises.stat(__classPrivateFieldGet(this, _FileFromPath_path, "f"));58 if (mtimeMs > this.lastModified) {59 throw new node_domexception_1.default(MESSAGE, "NotReadableError");60 }61 if (this.size) {62 yield* (0, fs_1.createReadStream)(__classPrivateFieldGet(this, _FileFromPath_path, "f"), {63 start: __classPrivateFieldGet(this, _FileFromPath_start, "f"),64 end: __classPrivateFieldGet(this, _FileFromPath_start, "f") + this.size - 165 });66 }67 }68 get [(_FileFromPath_path = new WeakMap(), _FileFromPath_start = new WeakMap(), Symbol.toStringTag)]() {69 return "File";70 }71}72function createFileFromPath(path, { mtimeMs, size }, filenameOrOptions, options = {}) {73 let filename;74 if ((0, isPlainObject_1.default)(filenameOrOptions)) {75 [options, filename] = [filenameOrOptions, undefined];76 }77 else {78 filename = filenameOrOptions;79 }80 const file = new FileFromPath({ path, size, lastModified: mtimeMs });81 if (!filename) {82 filename = file.name;83 }84 return new File_1.File([file], filename, {85 ...options, lastModified: file.lastModified86 });87}88function fileFromPathSync(path, filenameOrOptions, options = {}) {89 const stats = (0, fs_1.statSync)(path);90 return createFileFromPath(path, stats, filenameOrOptions, options);91}92exports.fileFromPathSync = fileFromPathSync;93async function fileFromPath(path, filenameOrOptions, options) {94 const stats = await fs_1.promises.stat(path);95 return createFileFromPath(path, stats, filenameOrOptions, options);96}97exports.fileFromPath = fileFromPath;98 