koajs / koa

Expressive middleware for node.js using ES2017 async functions
https://koajs.com
MIT License
35.23k stars 3.23k forks source link

How to send binary data #1020

Closed nikitaulshin closed 7 years ago

nikitaulshin commented 7 years ago

Hello!

I'm building an app using awesome Koa2. Could you please tell me how can I send binary data (i. e. ArrayBuffer)?

Thanks!

fengmk2 commented 7 years ago

Buffer Data

const buf = Buffer.alloc(1024);
ctx.body = buf;

Stream object

const stream = fs.createReadStream(__filename);
ctx.body = stream;
nikitaulshin commented 7 years ago

Thanks