@hyperbytes/wappler-file-to-binary-raw-text
Version:
Binary read file and return raw text
16 lines (15 loc) • 642 B
JavaScript
// JavaScript Document
const fs = require('fs').promises;
const { toSystemPath } = require('../../../lib/core/path');
exports.file2text = async function (options, name) {
const webfilepath = this.parseRequired(options.filepath, "*", "No File Specified");
const isDebugMode = this.parseOptional(options.logging, "*", false);
const filepath = toSystemPath(webfilepath);
isDebugMode && console.log("filepath]: " + filepath);
try {
const content = await fs.readFile(filepath, 'utf8');
return { status: 200, content: content };
} catch (err) {
return { status: 400, content: err.message };
}
};