Skip to content

Commit af095cb

Browse files
committed
Finally fully async.
1 parent a1f45b4 commit af095cb

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* Implements new GET response handlers: buffer - the response contains a buffer key with the buffer contents; stream - returns the HTTPS response itself which implements node.js's Readable Stream interface.
2121
* Adds a new s3.putStream() helper for PUT'ing streams to S3.
2222
* Adds a new s3.putBuffer() helper for PUT'ing buffers to S3.
23+
* Goes fully async by removing the only blocking call, fs.statSync(), when using PUT with file request body handler.
2324
* Unit testing coverage.
2425

2526
## v0.4.4

lib/aws.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,6 @@ var client = function (config) {
236236
}
237237
if (body.file) {
238238
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;
241239
}
242240
if ( ! headers['content-length']) {
243241
headers = tools.merge(headers, {'content-length': 0});

lib/internals.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,20 @@ var standardHeaders = function (config, method, headers, path, body, callback) {
374374
hdr = normalizeHeaders(hdr);
375375
if (body.file) {
376376
if ( ! hdr['content-type']) {
377-
mime.fileWrapper(p.resolve(body.file), function (err, res) {
377+
mime.fileWrapper(body.file, function (err, res) {
378378
if (err) {
379379
callback(err);
380380
} else {
381381
hdr['content-type'] = res;
382-
hdr.authorization = authorize(config, method, hdr, path);
383-
callback(null, hdr);
382+
fs.stat(body.file, function (err, stats) {
383+
if (err) {
384+
callback(err);
385+
} else {
386+
hdr['content-length'] = stats.size;
387+
hdr.authorization = authorize(config, method, hdr, path);
388+
callback(null, hdr);
389+
}
390+
});
384391
}
385392
});
386393
return;

0 commit comments

Comments
 (0)