The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/app/file-upload/server/lib/streamToBuffer.ts

13 lines
428 B

import type { Readable } from 'stream';
export const streamToBuffer = (stream: Readable): Promise<Buffer> =>
new Promise((resolve, reject) => {
const chunks: Array<Buffer> = [];
stream
.on('data', (data) => chunks.push(data))
.on('end', () => resolve(Buffer.concat(chunks)))
.on('error', (error) => reject(error))
// force stream to resume data flow in case it was explicitly paused before
.resume();
});