Class: TelestreamCloud::Uploader::FileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/telestream_cloud/uploader/file_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ FileReader

Returns a new instance of FileReader.



6
7
8
9
# File 'lib/telestream_cloud/uploader/file_reader.rb', line 6

def initialize(file)
  @file = file
  @mutex = Mutex.new
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



4
5
6
# File 'lib/telestream_cloud/uploader/file_reader.rb', line 4

def file
  @file
end

Instance Method Details

#[](range) ⇒ Object



11
12
13
14
15
16
# File 'lib/telestream_cloud/uploader/file_reader.rb', line 11

def [](range)
  @mutex.synchronize do
    file.seek(range.begin)
    file.read(range.size)
  end
end

#nameObject



22
23
24
# File 'lib/telestream_cloud/uploader/file_reader.rb', line 22

def name
  Pathname.new(file.path).basename
end

#sizeObject



18
19
20
# File 'lib/telestream_cloud/uploader/file_reader.rb', line 18

def size
  @size ||= file.size
end