API Docs for: 0.7.0
Show:

util.__global__ Class

Defined in: lib/util.js:1
Module: util

Utilities module

Methods

_authWithHeader

(
  • method
  • headers
  • queryObj
  • callback
  • [bucket]
  • [object]
  • [data]
)

Defined in lib/util.js:204

Authenticated with http header

Parameters:

  • method String

    Http method

  • headers Object

    Http header

  • queryObj Object

    Extra query string in object format

  • callback Function

    Function called when get response. callback supplied with http.Response object

  • [bucket] String optional

    bucket name

  • [object] String optional

    object name

  • [data] String optional

    object content

authWithUrl

(
  • params
  • callback
)

Defined in lib/util.js:243

URL 中包含签名示例: http://storage.aliyun.com/quotes/nelson?OSSAccessKeyId=44CF9590006BF252F707&Expires=1141889120 &Signature=vjbyPxybdZaNmGa%2ByT272YEAiv4%3D 在 URL 中实现签名,必须至少包含 Signature,Expires,OSSAccessKeyId 三个参数。Expires 这个参数的值是一个 UNIX 时间(自 UTC 时间 1970 年 1 月 1 号开始的秒数,详见 wiki),用于标识该 URL 的超时时间。如果 OSS 接收到这 个URL请求的时候晚于签名中包含的Expires参数时,则返回请求超时的错误码。 例如:当前时间是 1141889060,开发者希望创建一个 60 秒后自动失效的 URL,13 则可以设置 Expires 时间为 1141889120。 所有的 OSS 支持的请求和各种 Head 参数,在 URL 中进行签名的方法和上 节介绍的签名算法基本一样。主要区别如下:
1) 通过 URL 包含签名时,之前的 Date 参数换成 Expires 参数。
2) 不支持同时在 URL 和 Head 中包含签名。
3) 如果传入的 Signature,Expires,OSSAccessKeyId 出现不止一次,以第一次 为准。
4) 请求先验证请求时间是否晚于 Expires 时间,然后再验证签名。

Parameters:

  • params Object

    variable parameters,the following two are necessary:

    • method http method
    • headers http headers
    The following three are optional:
    • timeout expire millisecond after now
    • bucket bucket name
    • object object name

  • callback Function

    Callback function after OSS response, supplied with http.Response object

cryptoMD5

(
  • data
)
String

Defined in lib/util.js:192

Crypto data with MD5

Parameters:

  • data String

    Content need crypto

Returns:

String: 128 bit encrypted array encoding with base64

debugOutput

(
  • func
  • variable
  • variable
  • [sep]
)

Defined in lib/util.js:48

Debug mode variable output helper

Parameters:

  • func String

    function name contain the variable

  • variable String

    variable name

  • variable All

    value

  • [sep] String optional

    seperator for each output

debugOutput

(
  • func
  • variable
  • variable
  • [sep]
)

Defined in lib/util.js:28

Debug mode variable output helper

Parameters:

  • func String

    function name contain the variable

  • variable String

    variable name

  • variable All

    value

  • [sep] String optional

    seperator for each output

getCanonicalizedHeader

(
  • headers
)
String

Defined in lib/util.js:91

1) 将所有以“x-oss-”为前缀的 HTTP 请求头的名字转换成小写字母。如’X-OSS-Meta-Name: TaoBao’ 转换成’x-oss-meta-name: TaoBao’。
2) 将上一步得到的所有 HTTP 请求头按照字典序进行升序排列。
3) 如果有相同名字的请求头,则根据标准 RFC 2616, 4.2 章进行合并(两个值之间只用逗号分隔)。 如有两个名为’x-oss-meta-name’的请求头,对应的值分别为’TaoBao’和’Alipay’,则合并后 为:’x-oss-meta-name:TaoBao,Alipay’。
4) 删除请求头和内容之间分隔符两端出现的任何空格。如’x-oss-meta-name: TaoBao,Alipay’转换 成:’x-oss-meta-name:TaoBao,Alipay’。
5) 将所有的头和内容用’\n’分隔符分隔拼成最后的 CanonicalizedOSSHeader。

Parameters:

  • headers Object

    http header

Returns:

String: canonicalized header

getCanonicalizedResource

(
  • queryObj
  • [bucket]
  • [object]
)

Defined in lib/util.js:124

1) 将CanonicalizedResource 置成空字符串(“”)
2) 放入要访问的 OSS 资源:“ /BucketName/ObjectName”(无 ObjectName 则不填)
3) 如果请求的资源包括子资源(sub-resource),那么将所有的子资源按照字典序,从小到大排列并 以’&’为分隔符生成子资源字符串。在 CanonicalizedResource 字符串尾添加“?”和子资源字 符串。此时的 CanonicalizedResource 例子如:/BucketName/ObjectName?acl &uploadId=UploadId
4) 如果用户请求在查询字符串(query string)中指定了要重写(override)返回请求的 header 那么将这些查询字符串及其请求值按照字典序,从小到大排列,以’&’为分隔符,按参数的字典序添加到 CanonicalizedResource 中。此时的 CanonicalizedResource 例子: /BucketName/ObjectName?acl&response-content-type=ContentType & uploadId =UploadId

Parameters:

  • queryObj Object

    Extra query string in object format

  • [bucket] String optional

    bucket name

  • [object] String optional

    object name

getPathname

(
  • [bucket]
  • [object]
)
String

Defined in lib/util.js:14

Generate path name. Both bucket and object name are optional, but If bucket name not appeared,object name should disappear neither.

Parameters:

  • [bucket] String optional

    bucket name

  • [object] String optional

    object name

Returns:

String: formatted pathname

getSign

(
  • access_key_secret
  • method
  • headers
  • queryObj
  • [bucket]
  • [object]
)
String

Defined in lib/util.js:161

Sign message using hmac-sha1

Parameters:

  • access_key_secret String

    Personal access key secret

  • method String

    http method

  • headers Object

    http headers

  • queryObj Object

    Extra query string in object format

  • [bucket] String optional

    bucket name

  • [object] String optional

    object name

Returns:

String: hmac-sha1 sign message

getUnixTime

(
  • timeout
)
Number

Defined in lib/util.js:80

Get Unix time from 1970.1.1 to now in seconds

Parameters:

  • timeout Number

    expire timeout millisecond later

Returns:

Number: millisecond after unix time to timeout millisecond after

getUTCDate

(
  • timeout
)
String

Defined in lib/util.js:68

Get UTC format timeout millisecond fron now on

Parameters:

  • timeout Number

    millisecond from now on

Returns:

String: UTC format time