Class: Zip::ExtraField::Generic

Inherits:
Object
  • Object
show all
Defined in:
lib/zip/extra_field/generic.rb

Direct Known Subclasses

IUnix, NTFS, OldUnix, UniversalTime, Zip64, Zip64Placeholder

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.nameObject



9
10
11
# File 'lib/zip/extra_field/generic.rb', line 9

def self.name
  @name ||= to_s.split('::')[-1]
end

.register_mapObject



3
4
5
6
7
# File 'lib/zip/extra_field/generic.rb', line 3

def self.register_map
  return unless const_defined?(:HEADER_ID)

  ::Zip::ExtraField::ID_MAP[const_get(:HEADER_ID)] = self
end

Instance Method Details

#==(other) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/zip/extra_field/generic.rb', line 25

def ==(other)
  return false if self.class != other.class

  each do |k, v|
    return false if v != other[k]
  end
  true
end

#initial_parse(binstr) ⇒ Object

return field [size, content] or false



14
15
16
17
18
19
20
21
22
23
# File 'lib/zip/extra_field/generic.rb', line 14

def initial_parse(binstr)
  return false unless binstr

  if binstr[0, 2] != self.class.const_get(:HEADER_ID)
    warn 'WARNING: weird extra field header ID. Skip parsing it.'
    return false
  end

  [binstr[2, 2].unpack1('v'), binstr[4..-1]]
end

#to_c_dir_binObject



39
40
41
42
# File 'lib/zip/extra_field/generic.rb', line 39

def to_c_dir_bin
  s = pack_for_c_dir
  self.class.const_get(:HEADER_ID) + [s.bytesize].pack('v') << s
end

#to_local_binObject



34
35
36
37
# File 'lib/zip/extra_field/generic.rb', line 34

def to_local_bin
  s = pack_for_local
  self.class.const_get(:HEADER_ID) + [s.bytesize].pack('v') << s
end