Class: Archive::Ar::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/archive/ar/writer.rb

Instance Method Summary collapse

Constructor Details

#initialize(filenames) ⇒ Writer

Returns a new instance of Writer.



4
5
6
# File 'lib/archive/ar/writer.rb', line 4

def initialize(filenames)
  @filenames = filenames
end

Instance Method Details

#build_arObject



14
15
16
17
18
# File 'lib/archive/ar/writer.rb', line 14

def build_ar
  @filenames.collect do |f|
    build_ar_entry(f)
  end
end

#build_ar_entry(file) ⇒ Object



8
9
10
11
12
# File 'lib/archive/ar/writer.rb', line 8

def build_ar_entry(file)
  header = Archive::Ar::Format.build_header(file)
  data = File.read(file)
  [header, data].join
end

#write(dest_file, options = {}) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/archive/ar/writer.rb', line 20

def write(dest_file, options = {})
  File.open(dest_file, 'w') do |f|
    data = build_ar.join("")
    f.write(Archive::Ar::MAGIC)
    f.write(data)
  end
end