Class: TelestreamCloud::Qc::Uploader::FileReader

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileReader

Returns a new instance of FileReader.



10
11
12
13
14
# File 'lib/telestream_cloud_qc/uploader.rb', line 10

def initialize(path)
  @mutex = Mutex.new
  @path = path
  reopen
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



8
9
10
# File 'lib/telestream_cloud_qc/uploader.rb', line 8

def file
  @file
end

Instance Method Details

#[](range) ⇒ Object



16
17
18
19
20
21
# File 'lib/telestream_cloud_qc/uploader.rb', line 16

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

#closeObject



31
32
33
34
# File 'lib/telestream_cloud_qc/uploader.rb', line 31

def close
  @file.close
  @file = nil
end

#nameObject



27
28
29
# File 'lib/telestream_cloud_qc/uploader.rb', line 27

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

#reopenObject



36
37
38
# File 'lib/telestream_cloud_qc/uploader.rb', line 36

def reopen
  @file ||= File.open(@path)
end

#sizeObject



23
24
25
# File 'lib/telestream_cloud_qc/uploader.rb', line 23

def size
  @size ||= file.size
end