Sha256: f59b17bf1de80750af19103e8d43262d9a2a6d8bc5343326b343e717a27c84a2

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

module Zip
  class ExtraField::Generic
    def self.register_map
      if self.const_defined?(:HEADER_ID)
        ::Zip::ExtraField::ID_MAP[self.const_get(:HEADER_ID)] = self
      end
    end

    def self.name
      self.to_s.split("::")[-1]
    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)
        $stderr.puts "Warning: weired extra feild header ID. skip parsing"
        return false
      end
      [binstr[2, 2].unpack("v")[0], binstr[4..-1]]
    end

    def ==(other)
      return false if self.class != other.class
      each do |k, v|
        v != other[k] and return false
      end
      true
    end

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

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

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
rubyzip-1.1.0 lib/zip/extra_field/generic.rb
rubyzip-1.0.0 lib/zip/extra_field/generic.rb
rubyzip-1.0.0.beta1 lib/zip/extra_field/generic.rb
superp-rubyzip-0.1.0 lib/zip/extra_field/generic.rb