Class: COS::COSDir
- Inherits:
-
ResourceOperator
- Object
- Struct::Base
- ResourceOperator
- COS::COSDir
- Defined in:
- lib/cos/dir.rb
Overview
COS目录资源
Instance Attribute Summary
Attributes inherited from ResourceOperator
Instance Method Summary collapse
-
#count ⇒ Integer
(also: #size)
获取当前目录下的文件及子目录总数.
-
#count_dirs ⇒ Integer
获取当前目录下的子目录数.
-
#count_files ⇒ Integer
获取当前目录下的文件数.
-
#create_folder(dir_name, options = {}) ⇒ COS::COSDir
(also: #mkdir)
在当前目录下创建子目录.
-
#download_all(file_store_path, options = {}) {|Float| ... } ⇒ Array<String>
批量下载当前目录中的所有文件(不含子目录).
-
#empty? ⇒ Boolean
判断当前目录是否是空的.
-
#hash_tree(options = {}) ⇒ Hash<Object>
获取当前目录Hash格式的目录树形结构, 可用于直接to_json.
-
#initialize(attrs = {}) ⇒ COS::COSDir
constructor
初始化.
-
#list(options = {}) ⇒ Enumerator<Object>
(also: #ls)
列出当前文件夹下的目录及文件.
-
#list_count(options = {}) ⇒ Hash
获取当前目录下得文件和子目录总数信息.
-
#tree(options = {}) ⇒ Hash
获取当前目录树形结构.
-
#upload(file_name, file_src, options = {}) {|Float| ... } ⇒ COS::COSFile
在当前目录中上传文件,自动判断使用分片上传,断点续传及自动重试,多线程上传.
-
#upload_all(file_src_path, options = {}) {|Float| ... } ⇒ Array<COS::COSFile>
批量上传本地目录中的所有文件至此目录.
Methods inherited from ResourceOperator
#created_at, #delete, #delete!, #exist?, #stat, #to_hash, #update, #updated_at
Methods included from Struct::Base::AttrHelper
#optional_attrs, #required_attrs
Constructor Details
#initialize(attrs = {}) ⇒ COS::COSDir
初始化
26 27 28 29 |
# File 'lib/cos/dir.rb', line 26 def initialize(attrs = {}) super(attrs) @type = 'dir' end |
Instance Method Details
#count ⇒ Integer Also known as: size
获取当前目录下的文件及子目录总数
266 267 268 |
# File 'lib/cos/dir.rb', line 266 def count bucket.count(path) end |
#count_dirs ⇒ Integer
获取当前目录下的子目录数
286 287 288 |
# File 'lib/cos/dir.rb', line 286 def count_dirs bucket.count_dirs(path) end |
#count_files ⇒ Integer
获取当前目录下的文件数
277 278 279 |
# File 'lib/cos/dir.rb', line 277 def count_files bucket.count_files(path) end |
#create_folder(dir_name, options = {}) ⇒ COS::COSDir Also known as: mkdir
在当前目录下创建子目录
239 240 241 |
# File 'lib/cos/dir.rb', line 239 def create_folder(dir_name, = {}) bucket.create_folder("#{path}#{dir_name}", ) end |
#download_all(file_store_path, options = {}) {|Float| ... } ⇒ Array<String>
Note:
sdk会自动创建本地目录
批量下载当前目录中的所有文件(不含子目录)
146 147 148 |
# File 'lib/cos/dir.rb', line 146 def download_all(file_store_path, = {}, &block) bucket.download_all(self, file_store_path, , &block) end |
#empty? ⇒ Boolean
判断当前目录是否是空的
295 296 297 |
# File 'lib/cos/dir.rb', line 295 def empty? bucket.empty?(path) == 0 end |
#hash_tree(options = {}) ⇒ Hash<Object>
获取当前目录Hash格式的目录树形结构, 可用于直接to_json
:resource => {name: '', mtime: ''...,
:children => [
=> resource, :children => [...],
=> resource, :children => [...],
...
]
}
227 228 229 |
# File 'lib/cos/dir.rb', line 227 def hash_tree( = {}) bucket.hash_tree(self, ) end |
#list(options = {}) ⇒ Enumerator<Object> Also known as: ls
列出当前文件夹下的目录及文件
173 174 175 |
# File 'lib/cos/dir.rb', line 173 def list( = {}) bucket.list(path, ) end |
#list_count(options = {}) ⇒ Hash
获取当前目录下得文件和子目录总数信息
257 258 259 |
# File 'lib/cos/dir.rb', line 257 def list_count( = {}) bucket.list_count(path, ) end |
#tree(options = {}) ⇒ Hash
获取当前目录树形结构
:resource => resource,
:children => [
{:resource => resource, :children => [...],
=> resource, :children => [...],
...
]
}
203 204 205 |
# File 'lib/cos/dir.rb', line 203 def tree( = {}) bucket.tree(self, ) end |
#upload(file_name, file_src, options = {}) {|Float| ... } ⇒ COS::COSFile
在当前目录中上传文件,自动判断使用分片上传,断点续传及自动重试,多线程上传
65 66 67 |
# File 'lib/cos/dir.rb', line 65 def upload(file_name, file_src, = {}, &block) bucket.upload(self, file_name, file_src, , &block) end |
#upload_all(file_src_path, options = {}) {|Float| ... } ⇒ Array<COS::COSFile>
Note:
已存在的文件不会再次上传, 本地目录中的隐藏文件(已“.”开头的)不会上传 “.cpt”文件不会上传, 不会上传子目录
目录路径如: ‘/’, ‘path1’, ‘path1/path2’, sdk会补齐末尾的 ‘/’
批量上传本地目录中的所有文件至此目录
108 109 110 |
# File 'lib/cos/dir.rb', line 108 def upload_all(file_src_path, = {}, &block) bucket.upload_all(self, file_src_path, , &block) end |