Comparing version 0.0.1 to 1.0.0
102
index.js
@@ -6,2 +6,6 @@ /** | ||
var path = require('path'); | ||
var COS = require('./sdk/cos'); | ||
var fs = require('co-fs') | ||
var stream = require('stream'); | ||
var sdkConfig = require('./sdk/config') | ||
@@ -17,28 +21,92 @@ /** | ||
} | ||
this.bucket = options.bucket || 'tnpmnfs'; | ||
this.region = options.region || 'cn-south'; | ||
sdkConfig.APPID = options.APPID; | ||
sdkConfig.SECRET_ID = options.SECRET_ID; | ||
sdkConfig.SECRET_KEY = options.SECRET_KEY; | ||
} | ||
Client.prototype.upload = function* (filepath, options) { | ||
var destpath = this._getpath(options.key); | ||
yield ensureDirExists(destpath); | ||
Client.prototype.upload = function*(filepath, options) { | ||
var content = yield fs.readFile(filepath); | ||
yield fs.writeFile(destpath, content); | ||
return { key: options.key }; | ||
return yield this.uploadBuffer(content, options) | ||
}; | ||
Client.prototype.uploadBuffer = function* (content, options) { | ||
var filepath = this._getpath(options.key); | ||
yield ensureDirExists(filepath); | ||
yield fs.writeFile(filepath, content); | ||
return { key: options.key }; | ||
Client.prototype.uploadBuffer = function*(content, options) { | ||
var key = trimKey(options.key); | ||
var contentLength = content.length; | ||
var body = bufferToReadStream(content); // 转换成 read stream | ||
var params = { | ||
Bucket: this.bucket, /* 必须 */ | ||
Region: this.region, //cn-south、cn-north、cn-east /* 必须 */ | ||
Key: key, /* 必须 */ | ||
Body: body, /* 必须 */ | ||
ContentLength: contentLength, /* 必须 */ | ||
}; | ||
yield new Promise(function (resolve, reject) { | ||
COS.putObject(params, function (err, data) { | ||
if (err) { | ||
return reject(err); | ||
} | ||
resolve(data); // {ETag: 'xxxxxxx'} | ||
}); | ||
}) | ||
return {key: key}; | ||
}; | ||
Client.prototype.download = function* (key, savePath, options) { | ||
var filepath = this._getpath(key); | ||
var content = yield fs.readFile(filepath); | ||
yield fs.writeFile(savePath, content); | ||
Client.prototype.download = function*(key, savePath, options) { | ||
var key = trimKey(key); | ||
var params = { | ||
Bucket: this.bucket, /* 必须 */ | ||
Region: this.region, //cn-south、cn-north、cn-east /* 必须 */ | ||
Key: key, /* 必须 */ | ||
Output: savePath | ||
}; | ||
yield new Promise(function (resolve, reject) { | ||
COS.getObject(params, function (err, data) { | ||
if (err) { | ||
return reject(err); | ||
} | ||
resolve(data); | ||
}) | ||
}) | ||
}; | ||
Client.prototype.remove = function* (key) { | ||
var filepath = this._getpath(key); | ||
yield fs.unlink(filepath); | ||
Client.prototype.remove = function*(key) { | ||
var key = trimKey(key); | ||
var params = { | ||
Bucket: this.bucket, /* 必须 */ | ||
Region: this.region, //cn-south、cn-north、cn-east /* 必须 */ | ||
Key: key, /* 必须 */ | ||
}; | ||
yield new Promise(function (resolve, reject) { | ||
COS.deleteObject(params, function (err, data) { | ||
if (err) { | ||
return reject(err); | ||
} | ||
resolve(); | ||
}) | ||
}) | ||
}; | ||
function trimKey(key) { | ||
return key ? key.replace(/^\//, '') : ''; | ||
} | ||
function bufferToReadStream(buf) { | ||
// Initiate the source | ||
var bufferStream = new stream.PassThrough(); | ||
// Write your buffer | ||
bufferStream.end(buf); | ||
return bufferStream | ||
} |
{ | ||
"name": "cos-cnpm", | ||
"version": "0.0.1", | ||
"version": "1.0.0", | ||
"description": "tencent-cloud cos wrapper for cnpm", | ||
@@ -24,6 +24,12 @@ "main": "index.js", | ||
"dependencies": { | ||
"async": "^2.2.0", | ||
"co-fs": "^1.2.0", | ||
"eventproxy": "^0.3.5", | ||
"request": "^2.81.0", | ||
"xml2js": "^0.4.17" | ||
}, | ||
"devDependencies": { | ||
"co": "^4.6.0", | ||
"mocha": "^1.21.4" | ||
} | ||
} |
@@ -11,2 +11,20 @@ # cos-cnpm | ||
## Warning!!! | ||
Only support singleton. Don't initialize two `cos-cnpm` instance. | ||
## Usage | ||
```js | ||
var client = require('cos-cnpm')({ | ||
APPID: '', | ||
SECRET_ID: '', | ||
SECRET_KEY: '', | ||
bucket: 'tnpmnfs', | ||
// 从 https://github.com/tencentyun/cos-java-sdk-v5/blob/master/src/main/java/com/qcloud/cos/region/Region.java 中选择。默认是 cn-south 华南 | ||
region: 'cn-south', | ||
}) | ||
``` | ||
## API | ||
@@ -13,0 +31,0 @@ |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
131196
25
2719
1
44
5
2
10
1
+ Addedasync@^2.2.0
+ Addedco-fs@^1.2.0
+ Addedeventproxy@^0.3.5
+ Addedrequest@^2.81.0
+ Addedxml2js@^0.4.17
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasync@2.6.4(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedco-from-stream@0.0.0(transitive)
+ Addedco-fs@1.2.0(transitive)
+ Addedco-read@0.0.1(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddebug@2.2.0(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedeventproxy@0.3.5(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedms@0.7.1(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsax@1.4.1(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedthunkify@0.0.1(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedxml2js@0.4.23(transitive)
+ Addedxmlbuilder@11.0.1(transitive)