UNPKG

@petarmihaylov/node-raas

Version:

A tiny library and CLI for interacting with the Reports as a Service - RAAS - API from UKG - Ultimate Kronos Group. This project is maintained by the team behind RaasTastic and the community. It provides a balanced set of features that should suit a broad

34 lines (33 loc) 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.saveStream = exports.decodeStream = exports.blueMagenta = exports.FileExportExtensions = void 0; const tslib_1 = require("tslib"); const chalk_1 = tslib_1.__importDefault(require("chalk")); const fs = tslib_1.__importStar(require("node:fs")); var FileExportExtensions; (function (FileExportExtensions) { FileExportExtensions["XML"] = "xml"; })(FileExportExtensions = exports.FileExportExtensions || (exports.FileExportExtensions = {})); function blueMagenta(blueString, magentaString) { return `${chalk_1.default.blue(blueString)} ${chalk_1.default.magenta(magentaString)}`; } exports.blueMagenta = blueMagenta; function decodeStream(reportStream) { return Buffer.from(reportStream, 'base64').toString('utf-8'); } exports.decodeStream = decodeStream; async function saveStream(decodedStream, fileName, fileExtension) { // Create a writable stream const fileLocation = `${fileName}.${fileExtension}`; const writerStream = fs.createWriteStream(fileLocation); // Write the data to stream with encoding to be utf8 await writerStream.write(decodedStream, 'utf8'); // Mark the end of file writerStream.end(); // Handle stream events --> finish, and error writerStream.on('finish', () => console.log(`Report stream saved to ${fileLocation}`)); writerStream.on('error', function (err) { throw new Error(err.stack); }); } exports.saveStream = saveStream;