Created
April 14, 2020 09:04
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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