class CPIO::ArchiveHeader
Constants
- FieldDefaults
- FieldMaxValues
- Fields
- HeaderSize
- HeaderUnpackFormat
- Magic
Public Class Methods
from(io)
click to toggle source
# File lib/excavate/extractors/cpio/cpio_old_format.rb, line 59 def self.from(io) data = io.read(HeaderSize) verify_size(data) verify_magic(data) new(unpack_data(data)) end
new(attrs)
click to toggle source
# File lib/excavate/extractors/cpio/cpio_old_format.rb, line 54 def initialize(attrs) @attrs = attrs check_attrs end
with_defaults(opts)
click to toggle source
# File lib/excavate/extractors/cpio/cpio_old_format.rb, line 66 def self.with_defaults(opts) name = opts[:name] defaults = FieldDefaults.merge(:mode => opts[:mode], :filesize => opts[:filesize], :namesize => name.size + 1) new(defaults) end
Private Class Methods
unpack_data(data)
click to toggle source
# File lib/excavate/extractors/cpio/cpio_old_format.rb, line 101 def self.unpack_data(data) contents = {} data.unpack(HeaderUnpackFormat).zip(Fields) do |(chunk,(size,name))| contents[name] = Integer("0#{chunk}") end contents end
verify_magic(data)
click to toggle source
# File lib/excavate/extractors/cpio/cpio_old_format.rb, line 95 def self.verify_magic(data) unless data[0..Magic.size - 1] == Magic raise ArchiveFormatError, "Archive does not seem to be a valid CPIO archive with ASCII headers." end end
verify_size(data)
click to toggle source
# File lib/excavate/extractors/cpio/cpio_old_format.rb, line 89 def self.verify_size(data) unless data.size == HeaderSize raise ArchiveFormatError, "Header is not long enough to be a valid CPIO archive with ASCII headers." end end
Public Instance Methods
to_data()
click to toggle source
# File lib/excavate/extractors/cpio/cpio_old_format.rb, line 72 def to_data Fields.collect do |(width,name)| raise ArchiveFormatError, "Expected header to have key #{name}" unless @attrs.has_key?(name) val = @attrs[name].respond_to?(:to_proc) ? @attrs[name].call : @attrs[name] raise ArchiveFormatError, "Header value for #{name} exceeds max length of #{FieldMaxValues[name]}" if val > FieldMaxValues[name] sprintf("%0*o", Fields.rassoc(name).first, val) end.join('') end
Private Instance Methods
check_attrs()
click to toggle source
# File lib/excavate/extractors/cpio/cpio_old_format.rb, line 83 def check_attrs [:mode, :namesize, :filesize].each do |attr| raise ArgumentError, "#{attr.inspect} must be given" if !@attrs.has_key?(attr) end end