mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 21:57:51 +00:00
21 lines
572 B
TypeScript
21 lines
572 B
TypeScript
|
import { ReadStream } from 'fs';
|
||
|
|
||
|
export async function buffer(stream: NodeJS.ReadableStream, bufferFile: string) {
|
||
|
const Promise = await import('bluebird');
|
||
|
const fs = await import('fs');
|
||
|
|
||
|
const fileWriteStream = fs.createWriteStream(bufferFile);
|
||
|
|
||
|
return new Promise(function(resolve, reject) {
|
||
|
return stream
|
||
|
.on('error', reject)
|
||
|
.on('end', resolve)
|
||
|
.pipe(fileWriteStream);
|
||
|
}).then(() => new Promise(function(resolve, reject) {
|
||
|
fs.createReadStream(bufferFile)
|
||
|
.on('open', function(this: ReadStream) {
|
||
|
resolve(this);
|
||
|
}).on('error', reject);
|
||
|
}));
|
||
|
};
|