From 22fbad2664f75c70c52e2db1ded31e762abf43d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A5=B6=E5=9F=B9=E6=B3=BD?= Date: Fri, 20 Oct 2017 01:06:58 -0500 Subject: [PATCH] fix: getStream support options.process (#304) closes https://github.com/ali-sdk/ali-oss/issues/300 --- lib/object.js | 6 ++++++ package.json | 1 + test/nodejs-processed-w200.png | Bin 21567 -> 21572 bytes test/object.test.js | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/lib/object.js b/lib/object.js index c979f5d54..0620c3cf7 100644 --- a/lib/object.js +++ b/lib/object.js @@ -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]; diff --git a/package.json b/package.json index b49bf737e..62c1ae88c 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/nodejs-processed-w200.png b/test/nodejs-processed-w200.png index f4ae7e0b094493fb7fb3395bd23401cf9a269761..dd0200178e1dc7eca8061000fa74c30ad2a9753b 100644 GIT binary patch delta 820 zcmV-41Izrsr~$;N0kAwk0rRsxK&lXbiF*Yn%qDThHWxDIm{#2Is**(dAImTSTY%u4UHQTJ2 z3)!5p*_cHgB&4U<&_$D5#@<8Td<^r}^GiHN1W1BUbGsbK(8;sdt%*Bk^WbS9~ zWgfs>zykA4JXr7`#;ngQA#=($Yvvy20y1aJz04VNj=^j)C(H&pnS0pgel`~} z-^7K2yKK&wbIgUznlWqUVm7C2HkdQUW`o#d%m#Cg#W@DddB$uq68AF?X7f$FrIVUc zEq~&z1YnFgV@}!r|JsA297%BifMPGDx&M{DBaMKhfN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YY*jWp2=O|(EiqlHSkV01yRXFhGT&@-B7p^d)i zFEuowophklgwbNOLKB?~bf!OaLiBp#(`Iyw4w`AA9WAtzb|X5_Obc3Qf__Id`lit( zx;A<}^J#;2w9rP{(L^(CsI=1^jSjjeEwqwW=!?$ihK63x{OXDhx}^!-(j}F4Ds5;+ tKhTL5dQ4~1D7~Kf^cRy5R2&!e*l&Q&3sk1N&i?=a002ovPDHLkV1krVi9`SZ diff --git a/test/object.test.js b/test/object.test.js index 25bb3ac90..899c04152 100644 --- a/test/object.test.js +++ b/test/object.test.js @@ -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)) { @@ -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');