2013-07-01 04:52:18 +08:00
|
|
|
module Zip
|
|
|
|
class ExtraField::Generic
|
|
|
|
def self.register_map
|
2017-06-29 10:57:12 +08:00
|
|
|
if const_defined?(:HEADER_ID)
|
2015-03-23 00:30:24 +08:00
|
|
|
::Zip::ExtraField::ID_MAP[const_get(:HEADER_ID)] = self
|
2013-07-01 04:52:18 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.name
|
2015-03-23 00:30:24 +08:00
|
|
|
@name ||= to_s.split('::')[-1]
|
2013-07-01 04:52:18 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# return field [size, content] or false
|
|
|
|
def initial_parse(binstr)
|
|
|
|
if !binstr
|
|
|
|
# If nil, start with empty.
|
|
|
|
return false
|
|
|
|
elsif binstr[0, 2] != self.class.const_get(:HEADER_ID)
|
2019-10-12 14:26:15 +08:00
|
|
|
warn 'WARNING: weird extra field header ID. Skip parsing it.'
|
2013-07-01 04:52:18 +08:00
|
|
|
return false
|
|
|
|
end
|
2015-03-21 16:27:44 +08:00
|
|
|
[binstr[2, 2].unpack('v')[0], binstr[4..-1]]
|
2013-07-01 04:52:18 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def ==(other)
|
|
|
|
return false if self.class != other.class
|
|
|
|
each do |k, v|
|
2015-03-21 15:48:05 +08:00
|
|
|
return false if v != other[k]
|
2013-07-01 04:52:18 +08:00
|
|
|
end
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_local_bin
|
|
|
|
s = pack_for_local
|
2015-03-21 16:27:44 +08:00
|
|
|
self.class.const_get(:HEADER_ID) + [s.bytesize].pack('v') << s
|
2013-07-01 04:52:18 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_c_dir_bin
|
|
|
|
s = pack_for_c_dir
|
2015-03-21 16:27:44 +08:00
|
|
|
self.class.const_get(:HEADER_ID) + [s.bytesize].pack('v') << s
|
2013-07-01 04:52:18 +08:00
|
|
|
end
|
|
|
|
end
|
2014-02-04 04:15:08 +08:00
|
|
|
end
|