class Ronin::Support::Archive::Tar::Writer
Handles writing tar encoded archive data.
@see rubydoc.info/stdlib/rubygems/Gem/Package/TarWriter
@api public
@since 1.0.0
Public Class Methods
Source
# File lib/ronin/support/archive/tar/writer.rb, line 69 def self.new(io_or_buffer, mode: 'w', &block) io = case io_or_buffer when String then StringIO.new(io_or_buffer,mode) else io_or_buffer end return super(io,&block) end
Initializes the tar writer.
@param [IO, StringIO, String] io_or_buffer
The IO object or buffer to write to. If a `String` is given, then it will be wrapped in a `StringIO` object using the optional `mode` argument.
@param [String] mode
The optional mode to initialize the `StringIO` object to wrap around the given buffer `String`.
@yield [tar]
If a block is given, it will be passed the new tar writer object.
@yieldparam [Writer] tar
The tar writer object.
@return [Writer]
The gzip writer object.
@example Initializing with an IO
object:
tar = Archive::Tar::Writer.new(io)
@example Initializing with a buffer:
buffer = "" tar = Archive::Tar::Writer.new(buffer)
@example Initializin with a buffer and append mode:
buffer = "foo" tar = Archive::Tar::Writer.new(buffer, mode: 'a')
Source
# File lib/ronin/support/archive/tar/writer.rb, line 94 def self.open(path,&block) if block File.open(path,'wb') do |file| new(file,&block) end else return new(File.new(path,'wb')) end end
Opens the tar archive file for writing.
@param [String] path
The path to the tar archive.
@yield [tar]
If a block is given, then it will be passed the new tar writer object.
@yieldparam [Writer] tar
The newly created tar writer object.
@return [Writer]
If no block is given, than the tar writer object will be returned.
Public Instance Methods
Source
# File lib/ronin/support/archive/tar/writer.rb, line 126 def add_file(name,contents=nil, mode: 0644, &block) if contents super(name,mode) do |io| io.write(contents) end else super(name,mode,&block) end end
Adds a file to the tar archive.
@param [String] name
The name or relative path of the new file.
@param [String, nil] contents
The optional contents of the file.
@param [Integer] mode
The permission mode for the new file.
@yield [file]
If a block is given, it will be yielded an output stream for the file that can be written to.
@yieldparam [Gem::Package::TarWriter::RestrictedStream] file
@return [self]
@see rubydoc.info/stdlib/rubygems/Gem/Package/TarWriter/RestrictedStream
Source
# File lib/ronin/support/archive/tar/writer.rb, line 174 def add_symlink(name,target, mode: 0777) super(name,target,mode) end
Adds a symlink to the tar archive.
@param [String] name
The name or relative path of the new symlink.
@param [String] target
The destination of the new symlink.
@param [Integer] mode
The permission mode of the new symlink.
Source
# File lib/ronin/support/archive/tar/writer.rb, line 158 def allocate_file(name,size, mode: 0644, &block) add_file_simple(name,mode,size,&block) end
Adds a file, with the exact size, to the tar archive.
@param [String] name
The name or relative path of the new file.
@param [Integer] size
The size of the file in bytes.
@param [Integer] mode
The permission mode for the new file.
@yield [file]
If a block is given, it will be yielded an output stream for the file that can be written to.
@yieldparam [Gem::Package::TarWriter::BoundedStream] file
@return [self]
@see rubydoc.info/stdlib/rubygems/Gem/Package/TarWriter/BoundedStream
Source
# File lib/ronin/support/archive/tar/writer.rb, line 189 def mkdir(name, mode: 0755) super(name,mode) end
Adds a directory to the tar archive.
@param [String] name
The name or relative path of the new directory.
@param [Integer] mode
The permission mode of the new directory.
@return [self]