Class: Archive::Tar::StreamReader
- Defined in:
- lib/archive/tar/stream_reader.rb
Constant Summary
Constants included from Archive::Tar
Instance Method Summary collapse
-
#initialize(stream, options = {}) ⇒ StreamReader
constructor
A new instance of StreamReader.
Methods inherited from Reader
#[], #build_index, #each, #entry?, #extract, #extract_all, #has_entry?, #index, #read, #stat, #stream
Methods included from Archive::Tar
#join_path, #normalize_path, #solve_path
Constructor Details
#initialize(stream, options = {}) ⇒ StreamReader
Returns a new instance of StreamReader.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/archive/tar/stream_reader.rb', line 26 def initialize(stream, = {}) = { block_size: 2 ** 19, reload_time: 32 }.merge() stream = IO.new(stream) if io.is_a? Integer if [:compression] == :auto raise "Automatic compression is not available for streams" end tmp_file = File.new("/tmp/" + rand(500000).to_s(16) + ".tar", "w+b") Thread.new do i = 0 until stream.eof? read = stream.read([:block_size]) tmp_file.write(read) self.build_index if i % [:reload_time] == 0 i += 1 end self.build_index end super(tmp_file, ) end |