diff --git a/build/actions/os.js b/build/actions/os.js index b317128d..b10f5603 100644 --- a/build/actions/os.js +++ b/build/actions/os.js @@ -1,5 +1,5 @@ (function() { - var Promise, _, commandOptions, form, fs, helpers, init, manager, patterns, resin, stepHandler, umount, unzip, visuals; + var Promise, _, commandOptions, form, fs, helpers, init, manager, patterns, resin, rindle, stepHandler, umount, unzip, visuals; fs = require('fs'); @@ -11,6 +11,8 @@ unzip = require('unzip2'); + rindle = require('rindle'); + resin = require('resin-sdk'); manager = require('resin-image-manager'); @@ -64,7 +66,7 @@ } else { output = fs.createWriteStream(options.output); } - return helpers.waitStream(stream.pipe(output))["return"](options.output); + return rindle.wait(stream.pipe(output))["return"](options.output); }).tap(function(output) { return console.info("The image was downloaded to " + output); }).nodeify(done); @@ -83,7 +85,7 @@ }); bar = new visuals.Progress('Writing Device OS'); step.on('burn', _.bind(bar.update, bar)); - return helpers.waitStream(step); + return rindle.wait(step); }; exports.configure = { diff --git a/build/utils/helpers.js b/build/utils/helpers.js index 93a55f80..4ef02b9c 100644 --- a/build/utils/helpers.js +++ b/build/utils/helpers.js @@ -46,14 +46,6 @@ } }; - exports.waitStream = function(stream) { - return new Promise(function(resolve, reject) { - stream.on('close', resolve); - stream.on('end', resolve); - return stream.on('error', reject); - }); - }; - exports.sudo = function(command) { var spawn; if (os.platform() === 'win32') { diff --git a/lib/actions/os.coffee b/lib/actions/os.coffee index fcabdcb8..bb883c8a 100644 --- a/lib/actions/os.coffee +++ b/lib/actions/os.coffee @@ -3,6 +3,7 @@ _ = require('lodash') Promise = require('bluebird') umount = Promise.promisifyAll(require('umount')) unzip = require('unzip2') +rindle = require('rindle') resin = require('resin-sdk') manager = require('resin-image-manager') visuals = require('resin-cli-visuals') @@ -54,7 +55,7 @@ exports.download = else output = fs.createWriteStream(options.output) - return helpers.waitStream(stream.pipe(output)).return(options.output) + return rindle.wait(stream.pipe(output)).return(options.output) .tap (output) -> console.info("The image was downloaded to #{output}") .nodeify(done) @@ -71,7 +72,7 @@ stepHandler = (step) -> step.on('burn', _.bind(bar.update, bar)) - return helpers.waitStream(step) + return rindle.wait(step) exports.configure = signature: 'os configure ' diff --git a/lib/utils/helpers.coffee b/lib/utils/helpers.coffee index 489feece..0430fcd4 100644 --- a/lib/utils/helpers.coffee +++ b/lib/utils/helpers.coffee @@ -33,12 +33,6 @@ exports.stateToString = (state) -> else throw new Error("Unsupported operation: #{state.operation.type}") -exports.waitStream = (stream) -> - return new Promise (resolve, reject) -> - stream.on('close', resolve) - stream.on('end', resolve) - stream.on('error', reject) - exports.sudo = (command) -> # Bypass privilege elevation for Windows for now. diff --git a/package.json b/package.json index f276cb7c..300a34c6 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "resin-settings-client": "^3.1.0", "resin-vcs": "^2.0.0", "rimraf": "^2.4.3", + "rindle": "^1.0.0", "tmp": "0.0.28", "umount": "^1.1.1", "underscore.string": "^3.1.1",