Skip to content

Commit

Permalink
fix: getStream support options.process (#304)
Browse files Browse the repository at this point in the history
closes #300
  • Loading branch information
PeterRao authored and fengmk2 committed Oct 20, 2017
1 parent fc3cd7f commit 22fbad2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ proto.get = function* get(name, file, options) {

proto.getStream = function* getStream(name, options) {
options = options || {};

if (options.process) {
options.subres = options.subres || {};
options.subres['x-oss-process'] = options.process;
}

var params = this._objectRequestParams('GET', name, options);
params.customResponse = true;
params.successStatuses = [200, 206, 304];
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"mocha": "^3.0.0",
"should": "^11.0.0",
"sinon": "^1.17.6",
"stream-equal": "^1.1.0",
"thunk-mocha": "^1.0.3",
"uglify-js": "^2.7.1"
},
Expand Down
Binary file modified test/nodejs-processed-w200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions test/object.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var stsConfig = require('./config').sts;
var urllib = require('urllib');
var copy = require('copy-to');
var mm = require('mm');
const streamEqual = require('stream-equal');

var tmpdir = path.join(__dirname, '.tmp');
if (!fs.existsSync(tmpdir)) {
Expand Down Expand Up @@ -914,6 +915,25 @@ describe('test/object.test.js', function () {
assert.equal(fs.readFileSync(tmpfile, 'utf8'), fs.readFileSync(__filename, 'utf8'));
});

it('should get image stream with image process', function* () {
var name = prefix + 'ali-sdk/oss/nodejs-test-getstream-image-1024x768.png';
var originImagePath = path.join(__dirname, 'nodejs-1024x768.png');
var processedImagePath = path.join(__dirname, 'nodejs-processed-w200.png');
var object = yield this.store.put(name, originImagePath, {
mime: 'image/png'
});

var result = yield this.store.getStream(name, {process: 'image/resize,w_200'});
assert.equal(result.res.status, 200);
var isEqual = yield streamEqual(result.stream, fs.createReadStream(processedImagePath));
assert(isEqual);
result = yield this.store.getStream(name,
{process: 'image/resize,w_200', subres: {'x-oss-process': 'image/resize,w_100'}});
assert.equal(result.res.status, 200);
isEqual = yield streamEqual(result.stream, fs.createReadStream(processedImagePath));
assert(isEqual);
});

it('should throw error when object not exists', function* () {
try {
yield this.store.getStream(this.name + 'not-exists');
Expand Down

0 comments on commit 22fbad2

Please sign in to comment.