Class: Mir::Disk::MultiPartFile
- Inherits:
-
Object
- Object
- Mir::Disk::MultiPartFile
- Defined in:
- lib/mir/disk/amazon.rb
Overview
Used to hide the inner details of multipart file uploads and downloads. It is important that this class does not throw any exceptions as these exceptions may be swallowed further up the stack by worker threads
Instance Attribute Summary collapse
-
#disk ⇒ Object
readonly
Returns the value of attribute disk.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#get(dest) ⇒ Object
Downloads the resource to the destination.
-
#initialize(disk, name) ⇒ MultiPartFile
constructor
A new instance of MultiPartFile.
-
#multipart? ⇒ Boolean
Whether the resource is broken into chunks on the remote store.
Constructor Details
#initialize(disk, name) ⇒ MultiPartFile
Returns a new instance of MultiPartFile.
213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/mir/disk/amazon.rb', line 213 def initialize(disk, name) @disk, @name = disk, name multiname = Utils.filename_with_sequence(name, 1) if disk.key_exists?(name) @multipart = false elsif disk.key_exists?(multiname) @multipart = true else raise Disk::RemoteFileNotFound end end |
Instance Attribute Details
#disk ⇒ Object (readonly)
Returns the value of attribute disk.
226 227 228 |
# File 'lib/mir/disk/amazon.rb', line 226 def disk @disk end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
226 227 228 |
# File 'lib/mir/disk/amazon.rb', line 226 def name @name end |
Instance Method Details
#get(dest) ⇒ Object
Downloads the resource to the destination. If the file is stored in parts it is download sequentially in pieces
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/mir/disk/amazon.rb', line 235 def get(dest) output = File.new(dest, "wb") begin if multipart? seq = 1 while part = Utils.filename_with_sequence(name, seq) do break unless disk.key_exists? part output.write disk.read(part) seq += 1 end else output.write disk.read(name) end rescue Exception => e Mir.logger.error e ensure output.close end end |
#multipart? ⇒ Boolean
Whether the resource is broken into chunks on the remote store
229 230 231 |
# File 'lib/mir/disk/amazon.rb', line 229 def multipart? @multipart end |