balena-cli/lib/utils/streams.coffee
Tim Perry e584dc43f7 Gzip images when uploading in resin deploy
Change-Type: minor
Connects-To: #549
2017-06-15 12:01:22 +02:00

18 lines
399 B
CoffeeScript

exports.buffer = (stream, bufferFile) ->
Promise = require('bluebird')
fs = require('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)