Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ks3

Package Overview
Dependencies
Maintainers
4
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ks3 - npm Package Compare versions

Comparing version 0.3.6 to 0.3.7

docs/app-0c945a27f43452df695771ddb60b3d14.js

12

bin/index.js

@@ -59,3 +59,3 @@ #!/usr/bin/env node

}else {
throw new Error(' region不存在,有效值: HANGZHOU|BEIJING|HONGKONG|AMERICA|SHANGHAI')
throw new Error(' region不存在,有效值: BEIJING|HONGKONG|AMERICA|SHANGHAI')
}

@@ -227,2 +227,3 @@ }

var bucket = results[2];
var region = results[3];
nconf.set('AK', ak);

@@ -233,2 +234,5 @@ nconf.set('SK', sk);

}
if( region !== '') {
nconf.set('REGION',region);
}
nconf.save();

@@ -350,3 +354,3 @@ }

if (!regionStr) {
var region = 'HANGZHOU';
var region = 'BEIJING';
nconf.set('REGION', region);

@@ -490,4 +494,4 @@ nconf.save();

if (!regionStr) {
//console.log(' 请输入Bucket所在位置(HANGZHOU|BEIJING|HONGKONG|AMERICA|SHANGHAI): ');
var region = 'HANGZHOU';
//console.log(' 请输入Bucket所在位置(BEIJING|HONGKONG|AMERICA|SHANGHAI): ');
var region = 'BEIJING';
nconf.set('REGION', region);

@@ -494,0 +498,0 @@ nconf.save();

@@ -43,3 +43,3 @@ # KS3 命令行文档

`-b --bucket` : 开发要使用哪个Bucket,非必须,可以在每个具体命令中指定
`-r --region` : Bucket所在Region,非必须,可在每个具体命令中指定,有效值为:HANGZHOU|BEIJING|HONGKONG|AMERICA|SHANGHAI
`-r --region` : Bucket所在Region,非必须,可在每个具体命令中指定,有效值为:BEIJING|HONGKONG|AMERICA|SHANGHAI

@@ -58,3 +58,3 @@ 也可以直接输入`ks3 init`进入交互模式

`--withsubdir` : 在上传文件夹的过程中,是否上传子文件夹,默认不上传,加上本参数,上传子文件夹内容
`-r --region` : Bucket所在Region,有效值为:HANGZHOU|BEIJING|HONGKONG|AMERICA|SHANGHAI
`-r --region` : Bucket所在Region,有效值为:BEIJING|HONGKONG|AMERICA|SHANGHAI

@@ -72,6 +72,6 @@ 例如:

// 也可以直接传递参数
ks3 upload "/Users/ren/Desktop/Life Of Johnson.txt" -b ks3-sdk-test -k "Life Of Johnson.txt" -r HANGZHOU
ks3 upload "/Users/ren/Desktop/Life Of Johnson.txt" -b ks3-sdk-test -k "Life Of Johnson.txt" -r BEIJING
```
说明:不指定region则默认为杭州region
说明:不指定region则默认为北京region
2. 把 `D:\Program Files (x86)\Foxmail` 整个文件夹(包括子文件夹)上传,如下:

@@ -97,3 +97,3 @@

`-p --path` : 下载文件的本地存储地址
`-r --region` : Bucket所在Region,有效值为:HANGZHOU|BEIJING|HONGKONG|AMERICA|SHANGHAI
`-r --region` : Bucket所在Region,有效值为:BEIJING|HONGKONG|AMERICA|SHANGHAI

@@ -109,3 +109,3 @@ 例如:

// 或者直接指定bucket名称
ks3 download -b ks3-sdk-test -k test_download.txt -p d:\test.txt -r HANGZHOU
ks3 download -b ks3-sdk-test -k test_download.txt -p d:\test.txt -r BEIJING
```

@@ -112,0 +112,0 @@ 说明:不指定region则默认为杭州region

@@ -16,2 +16,3 @@ var config = require('../../config');

var uploadMaxSize = config.uploadMaxSize;
var multipartUploadMinSize = 100 * 1024 * 1024; // 100 MB

@@ -141,139 +142,156 @@ /**

// 还会根据文件大小,进行简单上传和分块上传
if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
console.log(' ')
//debug(' 开始上传文件: ' + filePath);
self.config({
dataType: 'json'
});
nconf.file({
file: configFile
});
var contentType = require('mime').lookup(filePath) || '';
// 分块上传
async.auto({
/**
* 初始化配置文件,如果没有就新建一个
*/
init: function(callback) {
if (!fs.existsSync(configFile)) {
configInit(filePath, configFile, function(err) {
callback(err);
})
} else {
callback(null);
}
var stats = fs.statSync(filePath);
},
show: ['init', function(callback) {
console.log(' 开始上传文件: ' + filePath)
bar = new ProgressBar(' [:bar] :percent', {
total: nconf.get('count')
});
bar.curr = nconf.get('index');
bar.render();
callback(null)
}],
/**
* 获取uploadId,如果有就直接读取,没有就从服务器获取一个
*/
getUploadId: ['init', function(callback) {
var uploadId = nconf.get('uploadId');
if (fs.existsSync(filePath) && stats.isFile()) {
console.log(' 开始上传文件: ' + filePath);
debug(' 开始上传文件: ' + filePath);
if ( !! uploadId) {
callback(null, uploadId)
} else {
self.object.multitpart_upload_init(params, function(err, data, res) {
uploadId = data.InitiateMultipartUploadResult.UploadId;
nconf.set('uploadId', uploadId);
nconf.save();
callback(null, uploadId)
});
}
}],
/**
* 对文件进行上传
* 上传后要把信息写到本地缓存配置文件中
* 如果都上传完了,就把配置文件删除
* 并通知服务器,合并分块文件
*/
upload: ['getUploadId', function(callback, result) {
var uploadId = result.getUploadId;
var count = nconf.get('count');
var index = nconf.get('index');
var chunkSize = nconf.get('chunkSize');
var currentRetries = nconf.get('retries');
var fileSizeInBytes = stats["size"];
//if(fileSizeInBytes <= config.chunkSize) { //5M 以下put上传
if(fileSizeInBytes < multipartUploadMinSize) { //100 M 以下put上传
debug('使用`简单上传` 文件:' + filePath);
self.object.put({
filePath: filePath,
Key: key
},
function(err, data, res) {
if (cb) cb(err, data, res);
})
// 在报错的时候重试
function retry(err) {
debug('upload ERROR:', err);
if (currentRetries > config.retries) {
throw err
} else {
currentRetries = currentRetries + 1;
nconf.set('retries', currentRetries)
nconf.save();
console.log('第 ' + currentRetries + ' 次重试');
up();
}
}
// 真正往服务端传递数据
function up() {
debug('上传用时', 'index: ' + index)
var start = (index - 1) * chunkSize;
// 判断是否已经全部都传完了
if (index <= count) {
getFileContent(filePath, chunkSize, start, function(body) {
delete params.filePath;
params.UploadId = uploadId;
params.PartNumber = index;
params.body = body;
params.type = contentType;
debug('正在上传第 ', index, ' 块,总共: ', + count + ' 块');
}else { //分块上传
self.config({
dataType: 'json'
});
nconf.file({
file: configFile
});
var contentType = require('mime').lookup(filePath) || '';
// 分块上传
async.auto({
/**
* 初始化配置文件,如果没有就新建一个
*/
init: function(callback) {
if (!fs.existsSync(configFile)) {
configInit(filePath, configFile, function(err) {
callback(err);
})
} else {
callback(null);
}
try {
self.object.upload_part(params, function(err, data, res) {
if (err) {
retry(err);
} else {
bar.tick();
var etag = res.headers.etag;
nconf.set('index', index);
nconf.set('etags:' + index, etag);
nconf.save(function(err) {
if (err) throw err;
index = index + 1;
up();
},
show: ['init', function(callback) {
console.log(' 开始上传文件: ' + filePath)
bar = new ProgressBar(' [:bar] :percent', {
total: nconf.get('count')
});
bar.curr = nconf.get('index');
bar.render();
callback(null)
}],
/**
* 获取uploadId,如果有就直接读取,没有就从服务器获取一个
*/
getUploadId: ['init', function(callback) {
var uploadId = nconf.get('uploadId');
if ( !! uploadId) {
callback(null, uploadId)
} else {
self.object.multitpart_upload_init(params, function(err, data, res) {
uploadId = data.InitiateMultipartUploadResult.UploadId;
nconf.set('uploadId', uploadId);
nconf.save();
callback(null, uploadId)
});
}
}],
/**
* 对文件进行上传
* 上传后要把信息写到本地缓存配置文件中
* 如果都上传完了,就把配置文件删除
* 并通知服务器,合并分块文件
*/
upload: ['getUploadId', function(callback, result) {
var uploadId = result.getUploadId;
var count = nconf.get('count');
var index = nconf.get('index');
var chunkSize = nconf.get('chunkSize');
var currentRetries = nconf.get('retries');
// 在报错的时候重试
function retry(err) {
debug('upload ERROR:', err);
if (currentRetries > config.retries) {
throw err
} else {
currentRetries = currentRetries + 1;
nconf.set('retries', currentRetries)
nconf.save();
console.log('第 ' + currentRetries + ' 次重试');
up();
}
}
// 真正往服务端传递数据
function up() {
debug('上传用时', 'index: ' + index)
var start = (index - 1) * chunkSize;
// 判断是否已经全部都传完了
if (index <= count) {
getFileContent(filePath, chunkSize, start, function(body) {
delete params.filePath;
params.UploadId = uploadId;
params.PartNumber = index;
params.body = body;
params.type = contentType;
debug('正在上传第 ', index, ' 块,总共: ', + count + ' 块');
try {
self.object.upload_part(params, function(err, data, res) {
if (err) {
retry(err);
} else {
bar.tick();
var etag = res.headers.etag;
nconf.set('index', index);
nconf.set('etags:' + index, etag);
nconf.save(function(err) {
if (err) throw err;
index = index + 1;
up();
});
}
});
} catch(e) {
retry(e);
}
});
} catch(e) {
retry(e);
})
} else {
debug('发送合并请求');
delete params.filePath;
params.UploadId = uploadId;
params.body = generateCompleteXML(configFile);
self.object.upload_complete(params, function(err, data, res) {
if (err) throw err;
callback(err, data, res);
})
}
})
} else {
debug('发送合并请求');
delete params.filePath;
params.UploadId = uploadId;
params.body = generateCompleteXML(configFile);
self.object.upload_complete(params, function(err, data, res) {
if (err) throw err;
callback(err, data, res);
})
};
up();
}]
},
function(err, results) {
if (err) throw err;
//删除配置
fs.unlinkSync(configFile);
if (cb) {
cb(err, results.upload[0], results.upload[1]);
}
});
}
};
up();
}]
},
function(err, results) {
if (err) throw err;
//删除配置
fs.unlinkSync(configFile);
if (cb) {
cb(err, results.upload[0], results.upload[1]);
}
});
} else if (fs.existsSync(filePath) && fs.statSync(filePath).isDirectory()) { // 文件夹上传
} else if (fs.existsSync(filePath) && stats.isDirectory()) { // 文件夹上传
var fileList = util.walkFile(filePath, params.fileSetting);

@@ -298,3 +316,3 @@ nconf.file({

* 是因为如果中间有文件改动,会增加复杂度
* 现在只需要判断用户上传的这个文件之前有没有山穿过就好了
* 现在只需要判断用户上传的这个文件之前有没有上传过就好了
nconf.set('count',count);

@@ -312,3 +330,3 @@ nconf.set('index',index);

if (fs.statSync(file).isFile()) { // 碰到文件
if (fs.statSync(file).size > config.chunkSize) { // 大文件,复杂上传
if (fs.statSync(file).size >= multipartUploadMinSize) { // 大文件,复杂上传
debug('使用`分块上传`,正在上传第 ' + index + '/' + count + ' 个文件:' + file);

@@ -315,0 +333,0 @@ self.upload.start({

{
"name": "ks3",
"version": "0.3.6",
"version": "0.3.7",
"description": "本代码库为`金山云存储KS3`服务.主要提供`KS3 nodejs SDK`和`命令行工具`.",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc