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.
238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/mir/disk/amazon.rb', line 238 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.
251 252 253 |
# File 'lib/mir/disk/amazon.rb', line 251 def disk @disk end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
251 252 253 |
# File 'lib/mir/disk/amazon.rb', line 251 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
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/mir/disk/amazon.rb', line 260 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
254 255 256 |
# File 'lib/mir/disk/amazon.rb', line 254 def multipart? @multipart end |