Innovenergy_trunk/frontend/node_modules/testcafe-hammerhead/lib/request-pipeline/file-request/filesystem-resource.js

35 lines
1.3 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const base_resource_1 = __importDefault(require("./base-resource"));
const fs_1 = __importDefault(require("fs"));
const promisified_functions_1 = require("../../utils/promisified-functions");
const TARGET_IS_NOT_FILE = 'The target of the operation is not a file';
class FileSystemResource extends base_resource_1.default {
constructor(path) {
super(path);
}
_getStat() {
return (0, promisified_functions_1.stat)(this._path)
.then((stats) => ({ stats, err: null }), (err) => ({ stats: null, err }));
}
_createContentStream() {
this._contentStream = fs_1.default.createReadStream(this._path);
}
async init() {
const { err, stats } = await this._getStat();
this._error = err;
if (stats) {
if (!stats.isFile())
this._error = new Error(TARGET_IS_NOT_FILE);
await this._checkAccess(this._path);
}
if (!this._error)
this._createContentStream();
}
}
exports.default = FileSystemResource;module.exports = exports.default;