Skip to content

Commit

Permalink
Merge pull request #7 from resin-io/fix/download-bug
Browse files Browse the repository at this point in the history
Manually pipe data from the download to options.pipe
  • Loading branch information
Juan Cruz Viotti committed May 7, 2015
2 parents 6cb3ab4 + e276408 commit 5478446
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 4 additions & 1 deletion build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ exports.pipeRequest = function(options, callback, onProgress) {
if (options.pipe == null) {
throw new errors.ResinMissingOption('pipe');
}
return progress(connection.request(options)).on('progress', ProgressState.createFromNodeRequestProgress(onProgress)).on('error', callback).pipe(options.pipe).on('error', callback).on('close', callback);
options.pipe.on('error', callback).on('close', callback);
return progress(connection.request(options)).on('progress', ProgressState.createFromNodeRequestProgress(onProgress)).on('error', callback).on('end', callback).on('data', function(chunk) {
return options.pipe.write(chunk);
});
};

exports.sendRequest = function(options, callback) {
Expand Down
15 changes: 12 additions & 3 deletions lib/utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,21 @@ exports.pipeRequest = (options, callback, onProgress) ->
throw new errors.ResinMissingOption('pipe')

# TODO: Find a way to test this

options.pipe
.on('error', callback)
.on('close', callback)

progress(connection.request(options))
.on('progress', ProgressState.createFromNodeRequestProgress(onProgress))
.on('error', callback)
.pipe(options.pipe)
.on('error', callback)
.on('close', callback)
.on('end', callback)

# For some reason, piping the stream to options.pipe
# make the process exit suddenly after ~10s.
# This is most likely an issue with node-request.
.on 'data', (chunk) ->
options.pipe.write(chunk)

exports.sendRequest = (options, callback) ->
connection.request options, (error, response) ->
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
"request-progress": "^0.3.1",
"resin-errors": "^1.0.0",
"resin-settings-client": "^1.0.0",
"resin-token": "^1.0.0"
"resin-token": "^1.2.0"
}
}

0 comments on commit 5478446

Please sign in to comment.