Class: Zip::ExtraField::Generic

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

Direct Known Subclasses

IUnix, 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
  self.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
  if self.const_defined?(:HEADER_ID)
    ::Zip::ExtraField::ID_MAP[self.const_get(:HEADER_ID)] = self
  end
end

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  return false if self.class != other.class
  each do |k, v|
    v != other[k] and return false
  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)
  if !binstr
    # If nil, start with empty.
    return false
  elsif binstr[0, 2] != self.class.const_get(:HEADER_ID)
    $stderr.puts "Warning: weired extra feild header ID. skip parsing"
    return false
  end
  [binstr[2, 2].unpack("v")[0], binstr[4..-1]]
end

#to_c_dir_binObject



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

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



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

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