Skip to content

Commit

Permalink
自动计算分片大小
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Jan 16, 2018
1 parent 4257d09 commit 6a8042e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
19 changes: 15 additions & 4 deletions dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2347,7 +2347,7 @@ util.extend(COS.prototype, base);
util.extend(COS.prototype, advance);

COS.getAuthorization = util.getAuth;
COS.version = '0.3.6';
COS.version = '0.3.7';

module.exports = COS;

Expand Down Expand Up @@ -9963,7 +9963,7 @@ function sliceUploadFile(params, callback) {
var Region = params.Region;
var Key = params.Key;
var Body = params.Body;
var SliceSize = params.SliceSize || this.options.ChunkSize;
var ChunkSize = params.ChunkSize || params.SliceSize || this.options.ChunkSize;
var AsyncLimit = params.AsyncLimit;
var StorageClass = params.StorageClass || 'Standard';
var FileSize;
Expand Down Expand Up @@ -10009,7 +10009,7 @@ function sliceUploadFile(params, callback) {
Key: Key,
Body: Body,
FileSize: FileSize,
SliceSize: SliceSize,
SliceSize: ChunkSize,
AsyncLimit: AsyncLimit,
UploadData: UploadData,
onProgress: onProgress
Expand All @@ -10034,7 +10034,7 @@ function sliceUploadFile(params, callback) {
StorageClass: StorageClass,
Body: Body,
FileSize: FileSize,
SliceSize: SliceSize,
SliceSize: ChunkSize,
onHashProgress: onHashProgress
});
getUploadIdAndPartList.call(self, _params, function (err, UploadData) {
Expand All @@ -10050,6 +10050,17 @@ function sliceUploadFile(params, callback) {
// 获取上传文件大小
FileSize = Body.size || params.ContentLength;

// 控制分片大小
(function () {
var SIZE = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 1024 * 2, 1024 * 4, 1024 * 8, 1024 * 10];
var AutoChunkSize = 1024 * 1024;
for (var i = 0; i < SIZE.length; i++) {
AutoChunkSize = SIZE[i] * 1024 * 1024;
if (FileSize / AutoChunkSize < 10000) break;
}
ChunkSize = Math.max(ChunkSize, AutoChunkSize);
})();

if (FileSize === 0) {
params.Body = '';
self.putObject(params, callback);
Expand Down
2 changes: 1 addition & 1 deletion dist/cos-js-sdk-v5.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cos-js-sdk-v5",
"version": "0.3.6",
"version": "0.3.7",
"description": "cos js sdk v5",
"main": "index.js",
"scripts": {
Expand Down
17 changes: 14 additions & 3 deletions src/advance.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function sliceUploadFile(params, callback) {
var Region = params.Region;
var Key = params.Key;
var Body = params.Body;
var SliceSize = params.SliceSize || this.options.ChunkSize;
var ChunkSize = params.ChunkSize || params.SliceSize || this.options.ChunkSize;
var AsyncLimit = params.AsyncLimit;
var StorageClass = params.StorageClass || 'Standard';
var FileSize;
Expand Down Expand Up @@ -56,7 +56,7 @@ function sliceUploadFile(params, callback) {
Key: Key,
Body: Body,
FileSize: FileSize,
SliceSize: SliceSize,
SliceSize: ChunkSize,
AsyncLimit: AsyncLimit,
UploadData: UploadData,
onProgress: onProgress
Expand All @@ -81,7 +81,7 @@ function sliceUploadFile(params, callback) {
StorageClass: StorageClass,
Body: Body,
FileSize: FileSize,
SliceSize: SliceSize,
SliceSize: ChunkSize,
onHashProgress: onHashProgress,
});
getUploadIdAndPartList.call(self, _params, function (err, UploadData) {
Expand All @@ -97,6 +97,17 @@ function sliceUploadFile(params, callback) {
// 获取上传文件大小
FileSize = Body.size || params.ContentLength;

// 控制分片大小
(function () {
var SIZE = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 1024 * 2, 1024 * 4, 1024 * 8, 1024 * 10];
var AutoChunkSize = 1024 * 1024;
for (var i = 0; i < SIZE.length; i++) {
AutoChunkSize = SIZE[i] * 1024 * 1024;
if (FileSize / AutoChunkSize < 10000) break;
}
ChunkSize = Math.max(ChunkSize, AutoChunkSize);
})();

if (FileSize === 0) {
params.Body = '';
self.putObject(params, callback);
Expand Down
2 changes: 1 addition & 1 deletion src/cos.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ util.extend(COS.prototype, base);
util.extend(COS.prototype, advance);

COS.getAuthorization = util.getAuth;
COS.version = '0.3.6';
COS.version = '0.3.7';

module.exports = COS;

0 comments on commit 6a8042e

Please sign in to comment.