Class: Yobi::IOHandle
- Inherits:
-
Object
- Object
- Yobi::IOHandle
- Defined in:
- lib/yobi/io_handle.rb,
sig/yobi.rbs
Overview
A live Restic process streaming raw bytes to its own stdout, returned by
Restic#run_dump when no block is given. Satisfies Rack's Body
contract (#each, #close).
Unlike the block form, nothing closes this automatically. Call #close
yourself once done reading, in an ensure, so it still runs if reading
raises:
Instance Attribute Summary collapse
-
#io ⇒ IO
readonly
The readable end of the pipe Restic's stdout is wired to.
-
#pid ⇒ Integer
readonly
The Restic process's pid.
Instance Method Summary collapse
-
#close ⇒ void
Reaps the Restic process and raises based on its exit code.
- #closed? ⇒ Boolean
- #each {|chunk| ... } ⇒ void
-
#initialize(io, pid:, output:, argv:) ⇒ IOHandle
constructor
A new instance of IOHandle.
- #inspect ⇒ String
Constructor Details
#initialize(io, pid:, output:, argv:) ⇒ IOHandle
Returns a new instance of IOHandle.
26 27 28 29 30 31 32 |
# File 'lib/yobi/io_handle.rb', line 26 def initialize(io, pid:, output:, argv:) @io = io @pid = pid @output = output @argv = argv @closed = false end |
Instance Attribute Details
#io ⇒ IO (readonly)
Returns the readable end of the pipe Restic's stdout is wired to.
21 22 23 |
# File 'lib/yobi/io_handle.rb', line 21 def io @io end |
#pid ⇒ Integer (readonly)
Returns the Restic process's pid.
23 24 25 |
# File 'lib/yobi/io_handle.rb', line 23 def pid @pid end |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
Reaps the Restic process and raises based on its exit code. Safe to call more than once.
48 49 50 51 52 53 54 55 |
# File 'lib/yobi/io_handle.rb', line 48 def close return if @closed @closed = true @io.close unless @io.closed? _, status = Process.wait2(@pid) Restic.dispatch(exit_code: status.exitstatus, output: @output, argv: @argv) end |
#closed? ⇒ Boolean
35 36 37 |
# File 'lib/yobi/io_handle.rb', line 35 def closed? @closed end |
#each {|chunk| ... } ⇒ void
61 62 63 64 65 66 67 68 |
# File 'lib/yobi/io_handle.rb', line 61 def each loop do yield @io.readpartial(64 * 1024) rescue EOFError break end close end |
#inspect ⇒ String
40 41 42 |
# File 'lib/yobi/io_handle.rb', line 40 def inspect "#<#{self.class} pid=#{pid} closed=#{closed?}>" end |