Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turning the stream into a buffer. #48

Closed
WaqqasI opened this issue Aug 13, 2018 · 1 comment
Closed

Turning the stream into a buffer. #48

WaqqasI opened this issue Aug 13, 2018 · 1 comment

Comments

@WaqqasI
Copy link

WaqqasI commented Aug 13, 2018

I have this code which should turn the stream into a buffer with 'stream-into-array'. However, when utilising this buffer, it doesn't work. When using fs to turn it into a file it works well.
const stream = await screenshot(url, '900x1000', { crop: true, userAgent: 'Mozilla/5.0 (X11; CrOS x86_64 10718.71.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.87 Safari/537.36', css: 'adblock.css', delay: 3, scale: 1.5 }); let buffer; await toArray(stream) .then(async function (parts) { var buffers = [] for (var i = 0, l = parts.length; i < l ; ++i) { var part = parts[i] buffers.push((part instanceof Buffer) ? part : new Buffer(part)) } buffer = await Buffer.concat(buffers) })
For more context, I'll be sending this buffer through to discord through discord.js but it seems it's not suitable for it.

@sindresorhus
Copy link
Contributor

You should not turn it into an array, but rather into a buffer. You can use getStream.buffer() for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants