mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-23 23:42:24 +00:00
18 lines
402 B
CoffeeScript
18 lines
402 B
CoffeeScript
|
exports.buffer = (stream, bufferFile) ->
|
||
|
Promise = require('bluebird')
|
||
|
fs = require('mz/fs')
|
||
|
|
||
|
fileWriteStream = fs.createWriteStream(bufferFile)
|
||
|
|
||
|
new Promise (resolve, reject) ->
|
||
|
stream
|
||
|
.on('error', reject)
|
||
|
.on('end', resolve)
|
||
|
.pipe(fileWriteStream)
|
||
|
.then ->
|
||
|
new Promise (resolve, reject) ->
|
||
|
fs.createReadStream(bufferFile)
|
||
|
.on 'open', ->
|
||
|
resolve(this)
|
||
|
.on('error', reject)
|