Method: COS::Bucket#stat

Defined in:
lib/cos/bucket.rb

#stat(path = '') ⇒ COSFile|COSDir

Note:

如查询根目录(‘/’, ”)可以获取到bucket信息, 返回COSDir

获取文件或目录信息

Examples:

puts bucket.stat('path1/file').name

Parameters:

  • path (String) (defaults to: '')

    资源路径, 如: 目录‘path1/’, 文件‘path1/file’

Returns:

  • (COSFile|COSDir)

    如果是目录则返回COSDir资源对象,是文件则返回COSFile资源对象

Raises:



321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/cos/bucket.rb', line 321

def stat(path = '')
  data = client.api.stat(path, bucket: bucket_name)

  # 查询'/'获取的是bucket信息, 无name参数, 需要补全
  data[:name] = '' if data[:name].nil?

  if data[:filesize].nil?
    # 目录
    COSDir.new(data.merge({bucket: self, path: path}))
  else
    # 文件
    COSFile.new(data.merge({bucket: self, path: path}))
  end
end