Skip to content

Instantly share code, notes, and snippets.

@thakursaurabh1998
Created April 14, 2020 09:04
Show Gist options
  • Save thakursaurabh1998/d16309bfd8ec3da197702a603875ec7f to your computer and use it in GitHub Desktop.
Save thakursaurabh1998/d16309bfd8ec3da197702a603875ec7f to your computer and use it in GitHub Desktop.
Stream file and create a local buffer, after stream ends, use the buffer accordingly
const readStream = s3Mumbai.getObject(workbookfile).createReadStream();
const buffers = [];
readStream.on('data', data => {
buffers.push(data);
});
readStream.on('error', err => {
next(err);
});
readStream.on('end', () => {
const buffer = Buffer.concat(buffers);
// here you can convert your buffer to any other data type
// and here you call the next function you want to call
// after the whole file is loaded in the memory
next(null, buffer);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment