Class: Fastdfs::Client::Storage
- Extended by:
- Hook
- Defined in:
- lib/fastdfs-client/storage.rb
Instance Attribute Summary collapse
-
#group_name ⇒ Object
Returns the value of attribute group_name.
-
#host ⇒ Object
Returns the value of attribute host.
-
#options ⇒ Object
Returns the value of attribute options.
-
#port ⇒ Object
Returns the value of attribute port.
-
#socket ⇒ Object
Returns the value of attribute socket.
-
#store_path ⇒ Object
Returns the value of attribute store_path.
Instance Method Summary collapse
- #delete(path, group_name = nil) ⇒ Object
-
#initialize(host, port, store_path = nil, options = {}) ⇒ Storage
constructor
A new instance of Storage.
- #upload(file) ⇒ Object
Methods included from Hook
add_hook, after, before, ensure_hijacked, hooks, method_added
Constructor Details
#initialize(host, port, store_path = nil, options = {}) ⇒ Storage
Returns a new instance of Storage.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fastdfs-client/storage.rb', line 14 def initialize(host, port, store_path = nil, = {}) @host = host @port = port = || {} = store_path if store_path.is_a?(Hash) @socket = Socket.new(host, port, [:socket]) @extname_len = ProtoCommon::EXTNAME_LEN @size_len = ProtoCommon::SIZE_LEN @store_path = store_path || 0 end |
Instance Attribute Details
#group_name ⇒ Object
Returns the value of attribute group_name.
12 13 14 |
# File 'lib/fastdfs-client/storage.rb', line 12 def group_name @group_name end |
#host ⇒ Object
Returns the value of attribute host.
12 13 14 |
# File 'lib/fastdfs-client/storage.rb', line 12 def host @host end |
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/fastdfs-client/storage.rb', line 12 def end |
#port ⇒ Object
Returns the value of attribute port.
12 13 14 |
# File 'lib/fastdfs-client/storage.rb', line 12 def port @port end |
#socket ⇒ Object
Returns the value of attribute socket.
12 13 14 |
# File 'lib/fastdfs-client/storage.rb', line 12 def socket @socket end |
#store_path ⇒ Object
Returns the value of attribute store_path.
12 13 14 |
# File 'lib/fastdfs-client/storage.rb', line 12 def store_path @store_path end |
Instance Method Details
#delete(path, group_name = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fastdfs-client/storage.rb', line 29 def delete(path, group_name = nil) cmd = CMD::DELETE_FILE raise "path arguments is empty!" if path.blank? if group_name.blank? group_name = /^\/?(\w+)/.match(path)[1] path = path.gsub("/#{group_name}") end raise "group_name arguments is empty!" if group_name.blank? group_bytes = group_name.bytes.fill(0, group_name.length...ProtoCommon::GROUP_NAME_MAX_LEN) path_length = (group_bytes.length + path.bytes.length) @socket.write(cmd, (ProtoCommon.header_bytes(cmd, path_length) + group_bytes + path.bytes)) @socket.receive end |
#upload(file) ⇒ Object
25 26 27 |
# File 'lib/fastdfs-client/storage.rb', line 25 def upload(file) _upload(file) end |