Comparing version 4.0.1 to 4.1.0
4.1.0 / 2016-01-26 | ||
================== | ||
* refine put/putStream interfaces | ||
* add putACL & getACL | ||
* fix bug when endpoint is IP with port | ||
4.0.1 / 2016-01-25 | ||
@@ -3,0 +10,0 @@ ================== |
@@ -344,3 +344,3 @@ /** | ||
var isIP = this._isIP(ep.host); | ||
var isIP = this._isIP(ep.hostname); | ||
var isCname = this.options.cname; | ||
@@ -347,0 +347,0 @@ if (params.bucket && !isCname && !isIP) { |
@@ -47,7 +47,6 @@ /**! | ||
if (fileSize < minPartSize) { | ||
var data = { | ||
stream: this._createStream(file, 0, fileSize), | ||
size: fileSize | ||
}; | ||
var ret = yield this.putData(name, data, options); | ||
var stream = this._createStream(file, 0, fileSize); | ||
options.contentLength = fileSize; | ||
var ret = yield this.putStream(name, stream, options); | ||
if (options && options.progress) { | ||
@@ -54,0 +53,0 @@ yield options.progress(1); |
@@ -34,18 +34,26 @@ /**! | ||
/** | ||
* put an object from String(file path)/Buffer/ReadableStream | ||
* @param {String} name the object key | ||
* @param {Mixed} file String(file path)/Buffer/ReadableStream | ||
* @param {Object} options | ||
* @return {Object} | ||
*/ | ||
proto.put = function* (name, file, options) { | ||
if (is.readableStream(file)) { | ||
return yield this.putStream(name, file, options); | ||
} | ||
var content; | ||
options = options || {}; | ||
if (is.string(file)) { | ||
if (is.buffer(file)) { | ||
content = file; | ||
} else if (is.string(file)) { | ||
options.mime = options.mime || mime.lookup(path.extname(file)); | ||
var stream = fs.createReadStream(file); | ||
options.contentLength = yield this._getFileSize(file); | ||
return yield this.putStream(name, stream, options); | ||
} else if (is.readableStream(file)) { | ||
return yield this.putStream(name, file, options); | ||
} else { | ||
throw new TypeError('Must provide String/Buffer/ReadableStream for put.'); | ||
} | ||
var data = yield* this._getContent(file); | ||
return yield this.putData(name, data, options); | ||
}; | ||
proto.putData = function* (name, data, options) { | ||
options = options || {}; | ||
options.headers = options.headers || {}; | ||
@@ -56,7 +64,6 @@ this._convertMetaToHeaders(options.meta, options.headers); | ||
params.mime = options.mime; | ||
params.stream = data.stream; | ||
params.content = data.content; | ||
params.content = content; | ||
params.successStatuses = [200]; | ||
var result = yield* this.request(params); | ||
var result = yield this.request(params); | ||
@@ -70,6 +77,18 @@ return { | ||
/** | ||
* put an object from ReadableStream. If `options.contentLength` is | ||
* not provided, chunked encoding is used. | ||
* @param {String} name the object key | ||
* @param {Readable} stream the ReadableStream | ||
* @param {Object} options | ||
* @return {Object} | ||
*/ | ||
proto.putStream = function* (name, stream, options) { | ||
options = options || {}; | ||
options.headers = options.headers || {}; | ||
options.headers['Transfer-Encoding'] = 'chunked'; | ||
if (options.contentLength) { | ||
options.headers['Content-Length'] = options.contentLength; | ||
} else { | ||
options.headers['Transfer-Encoding'] = 'chunked'; | ||
} | ||
this._convertMetaToHeaders(options.meta, options.headers); | ||
@@ -82,3 +101,3 @@ var params = this._objectRequestParams('PUT', name, options); | ||
var result = yield* this.request(params); | ||
var result = yield this.request(params); | ||
@@ -96,3 +115,3 @@ return { | ||
var result = yield* this.request(params); | ||
var result = yield this.request(params); | ||
@@ -139,3 +158,3 @@ var data = { | ||
result = yield* this.request(params); | ||
result = yield this.request(params); | ||
@@ -167,3 +186,3 @@ if (needDestroy) { | ||
var result = yield* this.request(params); | ||
var result = yield this.request(params); | ||
@@ -183,3 +202,3 @@ return { | ||
var result = yield* this.request(params); | ||
var result = yield this.request(params); | ||
@@ -212,3 +231,3 @@ return { | ||
params.successStatuses = [200]; | ||
var result = yield* this.request(params); | ||
var result = yield this.request(params); | ||
@@ -253,3 +272,3 @@ var r = result.data; | ||
var result = yield* this.request(params); | ||
var result = yield this.request(params); | ||
@@ -326,2 +345,52 @@ var data = result.data; | ||
/* | ||
* Set object's ACL | ||
* @param {String} name the object key | ||
* @param {String} acl the object ACL | ||
* @param {Object} options | ||
*/ | ||
proto.putACL = function* (name, acl, options) { | ||
options = options || {}; | ||
options.subres = 'acl'; | ||
options.headers = options.headers || {}; | ||
options.headers['x-oss-object-acl'] = acl; | ||
name = this._objectName(name); | ||
var params = this._objectRequestParams('PUT', name, options); | ||
params.successStatuses = [200]; | ||
var result = yield this.request(params); | ||
return { | ||
res: result.res | ||
}; | ||
}; | ||
/* | ||
* Get object's ACL | ||
* @param {String} name the object key | ||
* @param {Object} options | ||
* @return {Object} | ||
*/ | ||
proto.getACL = function* (name, options) { | ||
options = options || {}; | ||
options.subres = 'acl'; | ||
name = this._objectName(name); | ||
var params = this._objectRequestParams('GET', name, options); | ||
params.successStatuses = [200]; | ||
params.xmlResponse = true; | ||
var result = yield this.request(params); | ||
return { | ||
acl: result.data.AccessControlList.Grant, | ||
owner: { | ||
id: result.data.Owner.ID, | ||
displayName: result.data.Owner.DisplayName, | ||
}, | ||
res: result.res | ||
}; | ||
}; | ||
proto.signatureUrl = function (name, options) { | ||
@@ -377,39 +446,2 @@ name = this._objectName(name); | ||
/** | ||
* get content from string(file path), buffer(file content), stream(file stream) | ||
* @param {Mix} file | ||
* @return {Buffer} | ||
* | ||
* @api private | ||
*/ | ||
proto._getContent = function* (file) { | ||
if (is.buffer(file)) { | ||
return { | ||
content: file, | ||
size: file.length, | ||
}; | ||
} | ||
var content = { | ||
stream: null, | ||
size: null | ||
}; | ||
if (is.string(file)) { | ||
content.size = yield* this._getFileSize(file); | ||
file = fs.createReadStream(file); | ||
eoe(file, function () { | ||
destroy(file); | ||
}); | ||
} | ||
if (!is.readableStream(file)) { | ||
throw new TypeError('upload file type error, support: localfile, Buffer and ReadStream'); | ||
} | ||
content.stream = file; | ||
return content; | ||
}; | ||
/** | ||
* generator request params | ||
@@ -416,0 +448,0 @@ * @return {Object} params |
@@ -41,3 +41,3 @@ /**! | ||
this.options = { | ||
endpoint: 'https://sts.aliyuncs.com', | ||
endpoint: options.endpoint || 'https://sts.aliyuncs.com', | ||
format: 'JSON', | ||
@@ -44,0 +44,0 @@ apiVersion: '2015-04-01', |
{ | ||
"name": "ali-oss", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"description": "aliyun oss(open storage service) node client", | ||
@@ -5,0 +5,0 @@ "main": "lib/client.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
120877
1883