Class: Archive::Tar::Minitar::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar.rb

Overview

Wraps a Archive::Tar::Minitar::Writer with convenience methods and wrapped stream management; Output only works with random access data streams. See Output::new for details.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Output

Creates a new Output object. If output is a stream object that responds to #read), then it will simply be wrapped. Otherwise, one will be created and opened using Kernel#open. When Output#close is called, the stream object wrapped will be closed.



808
809
810
811
812
813
814
815
# File 'lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar.rb', line 808

def initialize(output)
  if output.respond_to?(:write)
    @io = output
  else
    @io = ::File.open(output, "wb")
  end
  @tarwriter = Archive::Tar::Minitar::Writer.new(@io)
end

Class Method Details

.open(output) ⇒ Object

With no associated block, Output::open is a synonym for Output::new. If the optional code block is given, it will be passed the new writer as an argument and the Output object will automatically be closed when the block terminates. In this instance, Output::open returns the value of the block.



791
792
793
794
795
796
797
798
799
800
801
802
# File 'lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar.rb', line 791

def self.open(output)
  stream = Output.new(output)
  return stream unless block_given?

  begin
    res = yield stream
  ensure
    stream.close
  end

  res
end

Instance Method Details

#closeObject

Closes the Writer object and the wrapped data stream.



823
824
825
826
# File 'lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar.rb', line 823

def close
  @tarwriter.close
  @io.close
end

#tarObject

Returns the Writer object for direct access.



818
819
820
# File 'lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar.rb', line 818

def tar
  @tarwriter
end