Create CSV or PDF files without saving it to disc and stream it to AWS S3 Bucket

Viewed 220

I have to create 2 files 1. PDF and 2. CSV, Both should be generated on a successful result.

I can generate PDF from HTML template using html-pdf package, I can create file stream without actually saving the file to disk, then stream the file using streaming-s3 package.

My problem starts with CSV files.

Curerently I'm creating a CSV file on the disk,

let testCsvData = ["Line 1", "Line 2", "Line 3", ..., "Line n"];
const testCSV = path.join('./test.csv');
fs.writeFileSync(testCSV, testCsvData.join(os.EOL));

Then createReadStream and get the file stream to push.

let testStream = fs.createReadStream('./test.csv');

I don't want to save the CSV file to the disk and then get the file stream. Thats simply waste of space right! Is there any way that I can directly get the file stream without saving it?

0 Answers
Related