Class: Archive::Ar::Format

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

Class Method Summary collapse

Class Method Details

.extract_file(dest_dir, header, data, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/archive/ar/format.rb', line 26

def extract_file(dest_dir, header, data, options = {})
  file = File.join(dest_dir, header[:name])

  File.open(file, "w") do |f|
    f.write(data)
  end

  File.chmod(header[:mode], file)
  #FileUtils.chown(header[:owner], header[:group], file)
end

.read_global_header(io) ⇒ Object



5
6
7
8
9
# File 'lib/archive/ar/format.rb', line 5

def read_global_header(io)
  io.read(8).tap do |global_header|
    raise "Invalid header" unless global_header == Archive::Ar::MAGIC
  end
end

.read_header(io) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/archive/ar/format.rb', line 11

def read_header(io)
  block = io.read(60)
  h = block.unpack("A16 Z12 a6 a6 A8 Z10 Z2")
  {
    :name => h.shift,
    :modified => Time.at(h.shift.to_i),
    :owner => h.shift.to_i,
    :group => h.shift.to_i,
    :mode => h.shift.to_i(8),
    :start => io.tell,
    :size => h.shift.to_i,
    :magic => h.shift,
  }
end