Sha256: dc728e639c5b67e04f1bd330c5e13249aa4fc6fa9e2b0586aa1efb06a14dc83d

Contents?: true

Size: 631 Bytes

Versions: 1

Compression:

Stored size: 631 Bytes

Contents

require "rubygems/package"
require "zlib"
require_relative "../writer"

class Metacrunch::File::Writer::TarFileWriter
  def self.supports?(filename)
    !!filename[/\.tar\Z|\.tar\.gz\Z|\.tgz\Z/]
  end

  def initialize(filename)
    @io = File.open(filename, "w")
    @io = Zlib::GzipWriter.new(@io) if filename.end_with?("gz")
    @tar_writer = Gem::Package::TarWriter.new(@io)
  end

  def close
    @tar_writer.close
    @io.close
  end

  def write(options = {})
    @tar_writer.add_file_simple(options[:entry_name], 0644, options[:content].bytesize) do |_tar_entry|
      _tar_entry.write(options[:content])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
metacrunch-2.2.3 lib/metacrunch/file/writer/tar_file_writer.rb