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_file:, argv:) ⇒ IOHandle
constructor
A new instance of IOHandle.
Constructor Details
#initialize(io, pid:, output_file:, argv:) ⇒ IOHandle
Returns a new instance of IOHandle.
29 30 31 32 33 34 35 |
# File 'lib/yobi/io_handle.rb', line 29 def initialize(io, pid:, output_file:, argv:) @io = io @pid = pid @output_file = output_file @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.
46 47 48 49 50 51 52 53 |
# File 'lib/yobi/io_handle.rb', line 46 def close return if @closed @closed = true @io.close unless @io.closed? _, status = Process.wait2(@pid) Restic.dispatch(exit_code: status.exitstatus, output: Yobi::ResticOutput.new(@output_file), argv: @argv) end |
#closed? ⇒ Boolean
38 39 40 |
# File 'lib/yobi/io_handle.rb', line 38 def closed? @closed end |