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

cos-cnpm

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cos-cnpm - npm Package Compare versions

Comparing version 0.0.1 to 1.0.0

.idea/vcs.xml

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

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