@realitydefender/realitydefender
Version:
SDK for the Reality Defender API for deepfake detection
40 lines (39 loc) • 1.24 kB
JavaScript
;
/**
* File handling utilities
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.readFileContent = readFileContent;
exports.getFileName = getFileName;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const errors_1 = require("../errors");
/**
* Validates that a file exists and reads its content
* @param filePath Path to the file
* @returns File contents as a Buffer
*/
function readFileContent(filePath) {
// Validate file exists
if (!fs_1.default.existsSync(filePath)) {
throw new errors_1.RealityDefenderError(`File not found: ${filePath}`, 'invalid_file');
}
try {
// Read file content
return fs_1.default.readFileSync(filePath);
}
catch (error) {
throw new errors_1.RealityDefenderError(`Failed to read file: ${error.message}`, 'invalid_file');
}
}
/**
* Extracts the filename from a file path
* @param filePath Path to the file
* @returns Base filename
*/
function getFileName(filePath) {
return path_1.default.basename(filePath);
}