UNPKG

ks3

Version:

本代码库为`金山云存储KS3`服务.主要提供`KS3 nodejs SDK`和`命令行工具`.

165 lines (157 loc) 5.46 kB
var KS3 = require('..'); var should = require('should'); require('should-http'); var fs = require('fs'); var path = require('path'); var { ak, sk, bucketName, region, prefix} = require('./config') const { testTagging } = require('./util') var bucketName = 'test-sdk-' + (+new Date()); var client = new KS3(ak, sk, bucketName, region); var debug = require('debug')('test-upload'); var key = 'multipartUpload/bigFile.tmp-' + (new Date()); console.log('prefix', prefix) var acl = 'public-read'; var headers = { 'x-kss-acl': acl, 'x-kss-tagging': 'aaa=sss&test=+ - . = _ : / @', 'x-kss-server-side-encryption': 'AES256' } var tmpFilePath = path.join(__dirname, ('./assets/bigFileOver100M.tmp' + (Date.now()))); /** * 测试分块拷贝 */ describe('sliceCopyFile', function() { before(function (done) { client.bucket.put({ Bucket: bucketName, ACL: acl }, function(err, data, res) { console.log('bucket created:', bucketName, err, data, res.statusCode) should.not.exist(err); res.should.have.status(200); done() }); }) describe('upload a big file', function() { before(function() { /** * 创建一个大于100M的文件 */ var mock_data = '金山云CDN服务将用户内容分发到全球700余个边缘节点,提高用户访问网站的响应速度与网站的可用性,通过智能监控实时调度异常节点资源,保证全局性能和可用性, 控制台可以帮助用户完成新增CDN加速域名、刷新/预加载缓存目录、URL等配置任务,并提供数据分析等统计图表。本文档主要介绍CDN控制台操作手册。'; mock_data = Buffer.from(new Array(30).join(mock_data)); var unit_size = mock_data.length; var total = 100 * 1024* 1024 ; //100 MB var sumSize = 0; while(sumSize <= total) { fs.appendFileSync(tmpFilePath, mock_data); sumSize += unit_size; debug('sumSize: ' + sumSize); } }); it('upload a big file by multipart upload', function(done) { this.timeout(0); client.config({ multipartUploadMinSize: 5* 1024 * 1024 }); client.upload.start({ Bucket: bucketName, filePath: tmpFilePath, Key: key, headers }, function(err, data, res) { should.not.exist(err); res.should.have.status(200); done(); }); }); }); describe('copy a big file', function() { before(function (done) { client.advance.sliceCopyFile({ Bucket: bucketName, Key: key, DestinationObject: key + '-copy', DestinationBucket: bucketName, ACL: 'public-read', Headers: { 'x-kss-copy-source-if-unmodified-since': 'true', 'x-kss-copy-source-if-match': 'true' }, onProgress: function (progress) { if(progress % 10 === 0){ console.log('copy progress', progress + '%') } else if(progress === 100){ console.log('copy success!') } } }, function (err, data, res) { should.not.exist(err); res.should.have.status(200); done(); }) }) after(function () { }); it('head copy file check', function(done) { client.object.head({ Bucket: bucketName, Key: key + '-copy', }, function (err, data, res) { should.not.exist(err); res.should.have.status(200); console.log('head copy file compare', res.headers) done(); }) }), it('after upload, test exist custom header', function (done) { client.config({ dataType: 'json' }); client.object.getObjectTagging({ Bucket: bucketName, Key: key + '-copy', }, function (err, data, res, body) { should.not.exist(err); res.should.have.status(200); let compareTag = testTagging(data.Tagging, headers['x-' + prefix + '-tagging']); compareTag.should.be.true; done(); }) }) it('delete big file', function (done) { client.object.del({ Bucket: bucketName, Key: key + '-copy', }, function (err, data, res) { should.not.exist(err); res.should.have.status(204); done(); }) }) it('delete copy file', function (done) { client.object.del({ Bucket: bucketName, Key: key }, function (err, data, res) { should.not.exist(err); res.should.have.status(204); done(); }) }) it('delete bucket', function (done) { setTimeout(() => { client.bucket.del(function(err, data, res) { should.not.exist(err); res.should.have.status(204); // 删除bucket,成功的状态码为204 done(); }) }, 1000); }) }) after(function (done) { fs.unlinkSync(tmpFilePath); done(); }) });