Skip to content

Commit

Permalink
uploads to AWS S3 with ContentEncoding header if necessary; fixes stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jokeyrhyme committed Aug 10, 2013
1 parent 6257a34 commit e8750f2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/cdn/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,14 @@ CDN.prototype.executeUpload = function (action) {
dfrd = Q.defer();
options = {
Bucket: this.cfg.Bucket,
//ContentEncoding: '',
ContentType: action.file.headers['Content-Type'],
Key: action.file.path
};

if (action.file.headers['Content-Encoding']) {
options.ContentEncoding = action.file.headers['Content-Encoding'];
}

action.file.getBuffer().then(function (buffer) {
options.Body = buffer;
self.api.putObject(options, function (err) { // (err, res)
Expand Down
5 changes: 4 additions & 1 deletion lib/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ FileList.prototype.applyStrategy = function (strategy) {
dfrd.reject(new TypeError('provided strategy should be Array or String'));
return dfrd.promise;
}
// if (strategy.indexOf('clone') !== -1) {} // no work necessary
if (strategy.indexOf('clone') !== -1) {
dfrd.resolve(new FileList(this));
return dfrd.promise;
}
if (strategy.indexOf('gzip') !== -1) {
gzips = this.map(function (file) {
file.file = file;
Expand Down
7 changes: 6 additions & 1 deletion lib/gzippedfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ var GzippedFile = function (file) {
self.calculateMD5()
];
}).spread(function (buffer) {
self.size = Buffer.byteLength(buffer.toString());
// from the docs, I should not use buffer.length here
// but it happens to match Content-Length from AWS perfectly ???
// alternatives:
// - buffer.toString().length
// - Buffer.byteLength(buffer.toString())
self.size = buffer.length;
process.nextTick(function () {
dfrd.resolve(self);
});
Expand Down

0 comments on commit e8750f2

Please sign in to comment.