Class: Zip::ZipExtraField

Inherits:
Hash
  • Object
show all
Defined in:
lib/ruby_archive/handlers/rubyzip/zip/zip.rb

Defined Under Namespace

Classes: Generic, IUnix, UniversalTime

Constant Summary collapse

ID_MAP =
{}

Instance Method Summary collapse

Constructor Details

#initialize(binstr = nil) ⇒ ZipExtraField

start main of ZipExtraField < Hash



1794
1795
1796
# File 'lib/ruby_archive/handlers/rubyzip/zip/zip.rb', line 1794

def initialize(binstr = nil)
  binstr and merge(binstr)
end

Instance Method Details

#c_dir_lengthObject Also known as: c_dir_size



1862
1863
1864
# File 'lib/ruby_archive/handlers/rubyzip/zip/zip.rb', line 1862

def c_dir_length
  to_c_dir_bin.length
end

#create(name) ⇒ Object



1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
# File 'lib/ruby_archive/handlers/rubyzip/zip/zip.rb', line 1831

def create(name)
  field_class = nil
  ID_MAP.each { |id, klass|
    if klass.name == name
      field_class = klass
      break
    end
  }
  if ! field_class
	raise ZipError, "Unknown extra field '#{name}'"
  end
  self[name] = field_class.new()
end

#local_lengthObject Also known as: local_size, length, size



1865
1866
1867
# File 'lib/ruby_archive/handlers/rubyzip/zip/zip.rb', line 1865

def local_length
  to_local_bin.length
end

#merge(binstr) ⇒ Object



1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
# File 'lib/ruby_archive/handlers/rubyzip/zip/zip.rb', line 1798

def merge(binstr)
  binstr == "" and return
  i = 0 
  while i < binstr.length
    id = binstr[i,2]
    len = binstr[i+2,2].to_s.unpack("v")[0] 
    if id && ID_MAP.member?(id)
      field_name = ID_MAP[id].name
      if self.member?(field_name)
        self[field_name].mergea(binstr[i, len+4])
      else
        field_obj = ID_MAP[id].new(binstr[i, len+4])
        self[field_name] = field_obj
      end
    elsif id
      unless self["Unknown"]
        s = ""
        class << s
          alias_method :to_c_dir_bin, :to_s
          alias_method :to_local_bin, :to_s
        end
        self["Unknown"] = s
      end
      if ! len || len+4 > binstr[i..-1].length
        self["Unknown"] << binstr[i..-1]
        break;
      end
      self["Unknown"] << binstr[i, len+4]
    end
    i += len+4
  end
end

#to_c_dir_binObject



1854
1855
1856
1857
1858
1859
1860
# File 'lib/ruby_archive/handlers/rubyzip/zip/zip.rb', line 1854

def to_c_dir_bin
  s = ""
  each { |k, v|
    s << v.to_c_dir_bin
  }
  s
end

#to_local_binObject Also known as: to_s



1845
1846
1847
1848
1849
1850
1851
# File 'lib/ruby_archive/handlers/rubyzip/zip/zip.rb', line 1845

def to_local_bin
  s = ""
  each { |k, v|
    s << v.to_local_bin
  }
  s
end