Class: FasterS3::Part
- Inherits:
-
Object
- Object
- FasterS3::Part
- Defined in:
- lib/faster_s3/part.rb
Instance Attribute Summary collapse
-
#extra_bytes ⇒ Object
Returns the value of attribute extra_bytes.
-
#file_path ⇒ Object
Returns the value of attribute file_path.
-
#index ⇒ Object
Returns the value of attribute index.
-
#part_length ⇒ Object
Returns the value of attribute part_length.
Instance Method Summary collapse
- #byte_range ⇒ Object
- #download(s3_object) ⇒ Object
- #existing_size ⇒ Object
-
#initialize(file_path, index, part_length, extra_bytes) ⇒ Part
constructor
A new instance of Part.
- #part_path ⇒ Object
Constructor Details
#initialize(file_path, index, part_length, extra_bytes) ⇒ Part
Returns a new instance of Part.
4 5 6 7 8 9 |
# File 'lib/faster_s3/part.rb', line 4 def initialize(file_path, index, part_length, extra_bytes) self.file_path = file_path self.index = index self.part_length = part_length self.extra_bytes = extra_bytes end |
Instance Attribute Details
#extra_bytes ⇒ Object
Returns the value of attribute extra_bytes.
2 3 4 |
# File 'lib/faster_s3/part.rb', line 2 def extra_bytes @extra_bytes end |
#file_path ⇒ Object
Returns the value of attribute file_path.
2 3 4 |
# File 'lib/faster_s3/part.rb', line 2 def file_path @file_path end |
#index ⇒ Object
Returns the value of attribute index.
2 3 4 |
# File 'lib/faster_s3/part.rb', line 2 def index @index end |
#part_length ⇒ Object
Returns the value of attribute part_length.
2 3 4 |
# File 'lib/faster_s3/part.rb', line 2 def part_length @part_length end |
Instance Method Details
#byte_range ⇒ Object
15 16 17 18 19 20 |
# File 'lib/faster_s3/part.rb', line 15 def byte_range start = index * part_length end_pos = start + part_length + extra_bytes (start + existing_size)...end_pos end |
#download(s3_object) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/faster_s3/part.rb', line 26 def download(s3_object) return if byte_range.min == byte_range.max File.open(part_path, 'ab') do |file| s3_object.read(range: byte_range) do |chunk| file.write(chunk) end end end |
#existing_size ⇒ Object
22 23 24 |
# File 'lib/faster_s3/part.rb', line 22 def existing_size File.exists?(part_path) ? File.size(part_path) : 0 end |
#part_path ⇒ Object
11 12 13 |
# File 'lib/faster_s3/part.rb', line 11 def part_path "#{file_path}.part.#{index}" end |