Skip to content

Commit a1f45b4

Browse files
committed
Decoupled the blocking stat() call from the makeRequest() method.
1 parent 9aee412 commit a1f45b4

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

lib/aws.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ var client = function (config) {
234234
if ( ! path) {
235235
return;
236236
}
237+
if (body.file) {
238+
body.file = p.resolve(body.file);
239+
// XXX wrap into a callback in order to remove this blocking call
240+
headers['content-length'] = fs.statSync(body.file).size;
241+
}
237242
if ( ! headers['content-length']) {
238243
headers = tools.merge(headers, {'content-length': 0});
239244
}

lib/internals.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,8 @@ var makeRequest = function (config, options, body, handler, callback, requestId)
7474
haveBodyHandler = true;
7575
}
7676
if ( ! haveBodyHandler) {
77-
try {
78-
if ( ! body.file) {
79-
throw new Error('Invalid body handler, expecting a file path.');
80-
}
81-
var bf = p.resolve(body.file);
82-
// XXX wrap the body handler into a callback in order to remove this blocking call
83-
options.headers['content-length'] = fs.statSync(bf).size;
84-
} catch (err) {
85-
callback(err);
77+
if ( ! body.file) {
78+
callback(new Error('Invalid body handler, expecting a file path.'));
8679
return;
8780
}
8881
}
@@ -272,7 +265,7 @@ var makeRequest = function (config, options, body, handler, callback, requestId)
272265
return;
273266
}
274267
if ( ! haveBodyHandler) {
275-
var bfile = fs.ReadStream(bf);
268+
var bfile = fs.ReadStream(body.file);
276269
bfile.on('data', function (chunk) {
277270
if ( ! aborted) {
278271
request.write(chunk);

0 commit comments

Comments
 (0)