upyun-storage Version: 0.0.2 By @Jackson Tian

Upyun storage client

client: API索引


md5

MD5工具函数

函数 md5() md5
参数 data(String) 待求MD5值的字符串
返回 String md5值

signature

签名工具函数,详情参见http://docs.upyun.com/api/http_api/#UPYUN签名认证

函数 signature() signature
参数 method(String) HTTP请求方法
参数 uri(String) 路径
参数 date(String) GMT格式的时间字符串
参数 contentLength(Number) 内容长度
参数 password(String) 操作员的密码
返回 String md5值

handle

辅助函数,截获异常,并包装新异常对象

函数 handle() handle
参数 callback(Function) 回调函数

Client

辅助函数,截获异常,并包装新异常对象

函数 Client() Client
参数 oprator(String) 操作员
参数 password(String) 操作员的密码
参数 bucket(String) 又拍云空间名

setAddress

切换又拍云路线
Example:

client.setAddress('v0');
方法 Client.prototype.setAddress() setAddress
参数 version(String) 版本。v0:自动判断,v1:电信,v2:联通网通,v3:移动铁通

getAuthorization

生成Authorization值

方法 Client.prototype.getAuthorization() getAuthorization
参数 method(String) HTTP请求方法
参数 uri(String) 路径
参数 date(String) GMT格式的时间字符串
参数 contentLength(Number) 内容长度

makeOptions

生成urllib的opts对象

函数 makeOptions() makeOptions
参数 that(Object) client对象
参数 method(String) HTTP请求方法
参数 uri(String) 路径
参数 filepath(String) 文件的位置
参数 size(Number) 文件大小

putFile

上传文件
Example:

client.putFile('/path/to/file', '/file.tgz', function (err, data, res) {
 // TODO
});

Callback:

  • err, 异常对象
  • data, 得到的数据。本方法中,data中不包含任何信息
  • res, 响应HTTP response对象。
方法 Client.prototype.putFile() putFile
参数 filepath(String) 文件实际地址
参数 filename(String) 上传后的位于空间中的位置。假定空间为/,你的文件为file.js,那么就是/file.js
参数 callback(Function) 回调函数

putBuffer

上传文件(通过Buffer)
Example:

var buffer = fs.readFileSync('/path/to/file');
client.putFile(buffer, '/file.tgz', function (err, data, res) {
 // TODO
});

Callback:

  • err, 异常对象
  • data, 得到的数据。本方法中,data中不包含任何信息
  • res, 响应HTTP response对象。
方法 Client.prototype.putBuffer() putBuffer
参数 buffer(Buffer) 从文件中读取到的buffer
参数 filename(String) 上传后的位于空间中的位置。假定空间为/,你的文件为file.js,那么就是/file.js
参数 callback(Function) 回调函数

getFile

下载文件
Example:

client.getFile('/file.tgz', function (err, data, res) {
 fs.writeFile('/path/to/file', data);
});

Callback:

  • err, 异常对象
  • data, 得到的数据,即文件的Buffer。
  • res, 响应HTTP response对象。
方法 Client.prototype.getFile() getFile
参数 filename(String) 文件位于空间中的位置。
参数 callback(Function) 回调函数

pipe

流式下载文件
Example:

var writable = fs.createWriteStream('/path/to/file');
client.pipe('/file.tgz', writable);
方法 Client.prototype.pipe() pipe
参数 filename(String) 文件位于空间中的位置。
参数 writable(Stream) 可写流对象。下载获得的数据会pipe到该writable对象

getFileInfo

获取文件信息
Example:

client.getFileInfo('/file.tgz', function (err, data, res) {
 // data => {type: file, size: 1024, lastModified: some date}
});

Callback:

  • err, 异常对象
  • data, 文件信息,包含type、size和lastModified
  • res, 响应HTTP response对象。
方法 Client.prototype.getFileInfo() getFileInfo
参数 filename(String) 文件位于空间中的位置。
参数 callback(Function) 回调函数

deleteFile

删除文件
Example:

client.deleteFile('/file.tgz', function (err, data, res) {
 // TODO
});

Callback:

  • err, 异常对象
  • data, 响应对象。本函数中data无实际意义,没有err,即表示成功
  • res, 响应HTTP response对象。
方法 Client.prototype.deleteFile() deleteFile
参数 filename(String) 文件位于空间中的位置。
参数 callback(Function) 回调函数

putFolder

创建文件夹
Example:

client.putFolder('/folder/', function (err, list, res) {
 // TODO
});

Callback:

  • err, 异常对象
  • data, 响应对象。本函数中data无实际意义,没有err,即表示成功
  • res, 响应HTTP response对象。
方法 Client.prototype.putFolder() putFolder
参数 foldername(String) 文件夹位于空间中的位置。
参数 callback(Function) 回调函数

deleteFolder

删除文件夹
Example:

client.deleteFolder('/folder/', function (err, list, res) {
 // TODO
});

Callback:

  • err, 异常对象
  • data, 响应对象。本函数中data无实际意义,没有err,即表示成功
  • res, 响应HTTP response对象。
属性 Client.prototype.deleteFolder deleteFolder
参数 foldername(String) 文件夹位于空间中的位置。
参数 callback(Function) 回调函数

getFolder

获取文件夹的信息
Example:

client.getFolder('/folder/', function (err, list, res) {
 // list => [{name: 'test.js', type: 'file', size: 1024, lastModified: new Date()}]
});

Callback:

  • err, 异常对象
  • data, 文件夹信息,包含name、type、size和lastModified的数组
  • res, 响应HTTP response对象。
方法 Client.prototype.getFolder() getFolder
参数 dirpath(String) 文件夹位于空间中的位置。
参数 callback(Function) 回调函数

bucketUsage

获取空间的使用信息
Example:

client.bucketUsage(function (err, used) {
 // used => 1024
});

Callback:

  • err, 异常对象
  • data, 使用信息,使用量
  • res, 响应HTTP response对象
方法 Client.prototype.bucketUsage() bucketUsage
参数 callback(Function) 回调函数

create

根据操作员、密码和空间名创建client实例
Example:

var client = Client.create('oprator', 'password', 'bucket');
方法 Client.create() Client create
参数 oprator(String) 操作员
参数 password(String) 回调函数
参数 bucket(String) 空间名
返回 Object 创建的Client实例