Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually pipe data from the download to options.pipe #7

Merged
merged 1 commit into from
May 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
}
}