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

ks3

Package Overview
Dependencies
Maintainers
1
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.0.3 to 0.0.4

lib/api/download.js

132

bin/index.js

@@ -82,2 +82,10 @@ #!/usr/bin/env node

/**
* 下载文件,还不支持下载文件夹
*/
program.command('download').description('下载文件').option("-p --path [path]", "选择下载文件的存放地址").option("-b --bucket [bucket]", "下载文件所在的Bucket").option("-k --key [key]", "下载文件的名称").action(function(options) {
download(options);
});
program.version(KS3.version).usage('<command> [options]').parse(process.argv);

@@ -172,2 +180,3 @@ if (!program.args.length) program.help();

if (err) {
console.log(err);
throw err;

@@ -289,2 +298,3 @@ } else {

if (err) {
console.log(err);
throw err;

@@ -313,3 +323,6 @@ } else {

function(err, data, res) {
if (err) throw err;
if (err) {
console.log(err);
throw err;
}

@@ -324,1 +337,118 @@ console.log(flag + '\n 上传完毕');

/**
* 下载
*/
function download(options) {
var stepPath = ' PATH: ';
var stepBucket = ' Bucket: ';
var stepKey = ' Key: ';
var akStr = nconf.get('AK') || '';
var skStr = nconf.get('SK') || '';
var filePath = options.path || '';
var bucketStr = options.bucket || '';
var keyStr = options.key || '';
if (akStr === '' || skStr === '') {
console.error(' 还没有进行初始化设置,请先使用命令 `ks3 init` 进行初始化');
process.exit(0);
}
if (!filePath) {
console.log(' 请输入下载文件存放的地址')
promptly.prompt(stepPath, function(err, filePath) {
if (err) {
console.error(err);
return err.retry()
} else {
nconf.set('PATH', filePath);
nconf.save();
download({
path: filePath
});
}
});
if ( !! nconf.get('PATH')) {
process.stdin.emit('data', nconf.get('PATH'));
}
} else {
async.series([function(callback) {
if (!bucketStr) {
console.log(' 请输入要下载文件所在的Bucket: ')
promptly.prompt(stepBucket, {
validator: check.bucketName
},
function(err, bucket) {
if (err) {
console.error(err);
return err.retry()
} else {
nconf.set('BUCKET', bucket);
nconf.save();
callback(null, bucket);
}
});
if ( !! nconf.get('BUCKET')) {
process.stdin.emit('data', nconf.get('BUCKET'));
}
} else {
callback(null, bucketStr);
}
},
function(callback) {
if (!keyStr) {
console.log(' 请输入要下载文件的名称: ')
promptly.prompt(stepKey, {
validator: check.key
},
function(err, key) {
if (err) {
console.error(err);
return err.retry()
} else {
nconf.set('KEY', key);
nconf.save();
callback(null, key);
}
});
if ( !! nconf.get('KEY')) {
process.stdin.emit('data', nconf.get('KEY'));
}
} else {
callback(null, keyStr);
}
}], function(err, results) {
if (err) {
throw err;
} else {
var flag = "----------------------------";
var bucket = results[0];
var key = results[1];
nconf.set('BUCKET', bucket);
nconf.save();
console.log(' 开始下载');
console.log(flag);
var client = new KS3(akStr, skStr, bucket);
filePath = filePath.replace(/(\\\s)/ig, ' ');
client.download.start({
Bucket: bucket,
filePath: filePath,
Key: key
},
function(err, data, res) {
if (err){
console.log(err)
throw err;
}
console.log(flag + '\n 下载完毕');
});
}
})
}
}

3

bin/readme.md

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

- ks3 init
主要执行初始化操作.在初始化过程中,可以指定开发者的`AK`和`SK`.
主要执行初始化操作.在初始化过程中,可以指定开发者的`AK`和`SK`.
命令行使用分为两种模式: 直接指定,或者进入交互模式.在`交互模式`下,会指导你填写必须的参数.如果所需参数没有提供完全,也会进入`交互模式`.

@@ -38,0 +39,0 @@ ```

@@ -53,2 +53,3 @@ var request = require('./../request');

var bucketName = params.Bucket || this.bucketName || '';
var range = params.range || '';
if(!bucketName) {

@@ -61,5 +62,10 @@ throw new Error('require the bucket name');

uri: config.protocol + '://' + bucketName + '.' + config.baseUrl + resource,
resource: '/' + bucketName + resource
resource: '/' + bucketName + resource,
headers: {}
};
var reRange = /^bytes=(\d+)-(\d+)$/i;
if(range!==''&& reRange.test(range)){
req.headers['Range'] = range;
}
var authStr = auth.generateAuth(this.ak, this.sk, req);

@@ -412,3 +418,3 @@ var body = null;

putAcl: putAcl,
headObject: headObject,
head: headObject,
multitpart_upload_init: multitpart_upload_init,

@@ -415,0 +421,0 @@ upload_part:upload_part,

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

var configInit = function(filePath, configFile, cb) {
fs.open(filePath, 'r+', function(err, fd) {

@@ -113,3 +114,3 @@ if (err) throw err;

var key = util.encodeKey(params.Key) || null;
var filePath = path.resolve(__dirname, params.filePath) || null;
var filePath = path.resolve(process.cwd(), params.filePath) || null;

@@ -143,3 +144,3 @@ if (!bucketName) {

console.log(' ')
console.log(' 开始上传文件: ' + filePath);
//debug(' 开始上传文件: ' + filePath);
self.config({

@@ -167,3 +168,3 @@ dataType: 'json'

show: ['init', function(callback) {
bar = new ProgressBar(' uploadding [:bar] :percent', {
bar = new ProgressBar(' 开始上传文件: ' + filePath+' [:bar] :percent', {
total: nconf.get('count')

@@ -236,3 +237,3 @@ });

} else {
bar.tick(1);
bar.tick();
var etag = res.headers.etag;

@@ -253,3 +254,3 @@ nconf.set('index', index);

} else {
console.log('发送合并请求')
debug('发送合并请求')
delete params.filePath;

@@ -266,3 +267,2 @@ params.UploadId = uploadId;

up();
}]

@@ -273,3 +273,5 @@ },

fs.unlinkSync(configFile);
cb(err, results.upload[0], results.upload[1]);
if(cb){
cb(err, results.upload[0], results.upload[1]);
}
});

@@ -279,3 +281,3 @@ } else if (fs.existsSync(filePath) && fs.statSync(filePath).isDirectory()) { // 文件夹上传

var count = fileList.length;
barDir = new ProgressBar(' uploadding [:bar] :percent ', {
barDir = new ProgressBar(' 上传文件夹:'+filePath+' [:bar] :percent ', {
total: count

@@ -306,3 +308,3 @@ });

var key2 = key + file.replace(filePath, '');
console.log('\n正在上传文件: ', file);
//debug('\n正在上传文件: ', file);
debug('使用`简单上传` 文件:' + file);

@@ -309,0 +311,0 @@ self.object.put({

@@ -17,3 +17,3 @@ var debug = require('debug')('app');

['service', 'bucket', 'object', 'upload'].forEach(function(name) {
['service', 'bucket', 'object', 'upload','download'].forEach(function(name) {
var api = require('./api/' + name)

@@ -20,0 +20,0 @@ core[name] = {};

@@ -50,5 +50,6 @@ var urllib = require('urllib');

}
debug('data',data);
cb(rerr, data, res)
// 增加原始数据流,因为在写文件的时候
// `buf.toString` 会有问题
cb(rerr, data, res,result);
}

@@ -55,0 +56,0 @@ });

{
"name": "ks3",
"version": "0.0.3",
"version": "0.0.4",
"description": "",

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

@@ -29,2 +29,3 @@ var KS3 = require('..');

client.should.have.property('upload');
client.should.have.property('download');
});

@@ -31,0 +32,0 @@ });

@@ -6,2 +6,3 @@ var KS3 = require('..');

var _dataType = require('./../config').dataType;
var fs = require('fs');

@@ -81,6 +82,45 @@ var ak = process.env.AK || 'WRHLHOZQD3OY3VTROMGQ';

function(err, data, res) {
should.not.exist(err);
res.should.have.status(200);
client.object.get({
Bucket:bucketName,
Key:key
},function(err,data,res){
var fileName = path.join(__dirname,'assets/test_download_file.txt');
data.should.have.length(11);
fs.writeFileSync(fileName,data);
done();
});
});
});
it('upload a object with file content && get a object', function(done) {
var client = new KS3(ak, sk, bucketName);
var fileName = 'photo.jpg';
var filePath = path.join(__dirname,'./assets/'+fileName);
var key = 'test_upload_'+fileName;
client.object.put({
Bucket: bucketName,
Key: key,
filePath:filePath
},
function(err, data, res) {
client.object.get({
Bucket:bucketName,
Key:key
},function(err,data,res,originData){
var newFileName = path.join(__dirname,'assets/test_object_get_download_'+fileName);
fs.writeFileSync(newFileName,originData);
done();
});
});
});
it('get a not exists file', function(done) {
var client = new KS3(ak, sk, bucketName);
var key = 'file_no_exist.jpg';
client.object.get({
Bucket:bucketName,
Key:key
},function(err,data,res){
should.exist(err);
err.code.should.equal(404);
res.statusCode.should.equal(404);
done();
});

@@ -283,2 +323,3 @@ });

});
describe('all of object process', function() {

@@ -312,3 +353,3 @@ var content = 'Hello world';

it('should be return a 200 statuscode width head object', function(done) {
client.object.headObject({
client.object.head({
Key: key

@@ -315,0 +356,0 @@ },

@@ -14,2 +14,3 @@ var KS3 = require('..');

describe('upload a file', function() {

@@ -38,2 +39,4 @@ it('upload a object with file content', function(done) {

describe('upload a directory', function() {

@@ -83,4 +86,3 @@ it('upload a directory without subdirectory', function(done) {

});
});

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