class S3MediaServerApi::Uploader::FilePart
Attributes
first_byte[R]
@return [Integer]
last_byte[R]
@return [Integer]
size[R]
@return [Integer]
source[R]
@return [String,Pathname,File,Tempfile]
Public Class Methods
new(options = {})
click to toggle source
@option options [required,String,Pathname,File,Tempfile] :source @option options [required,Integer] :offset The file part will read
starting at this byte offset.
@option options [required,Integer] :size The maximum number of bytes to
read from the `:offset`.
# File lib/s3_media_server_api/file_part.rb, line 10 def initialize(options = {}) @source = options[:source] @first_byte = options[:offset] @last_byte = @first_byte + options[:size] @size = options[:size] end
Public Instance Methods
close()
click to toggle source
# File lib/s3_media_server_api/file_part.rb, line 42 def close @file.close if @file end
read(bytes = nil, output_buffer = nil)
click to toggle source
# File lib/s3_media_server_api/file_part.rb, line 29 def read(bytes = nil, output_buffer = nil) open_file unless @file read_from_file(bytes, output_buffer) end
rewind()
click to toggle source
# File lib/s3_media_server_api/file_part.rb, line 34 def rewind if @file @file.seek(@first_byte) @position = @first_byte end 0 end
Private Instance Methods
open_file()
click to toggle source
# File lib/s3_media_server_api/file_part.rb, line 48 def open_file @file = File.open(@source, 'rb') rewind end
read_from_file(bytes, output_buffer)
click to toggle source
# File lib/s3_media_server_api/file_part.rb, line 53 def read_from_file(bytes, output_buffer) if bytes data = @file.read([remaining_bytes, bytes].min) data = nil if data == '' else data = @file.read(remaining_bytes) end @position += data ? data.bytesize : 0 output_buffer ? output_buffer.replace(data || '') : data end
remaining_bytes()
click to toggle source
# File lib/s3_media_server_api/file_part.rb, line 64 def remaining_bytes @last_byte - @position end