Class: Rant::Archive::Rubyzip::ZipExtraField

Inherits:
Hash
  • Object
show all
Defined in:
lib/rant/archive/rubyzip.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


1484
1485
1486
# File 'lib/rant/archive/rubyzip.rb', line 1484

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

Instance Method Details

#c_dir_lengthObject Also known as: c_dir_size


1552
1553
1554
# File 'lib/rant/archive/rubyzip.rb', line 1552

def c_dir_length
  to_c_dir_bin.length
end

#create(name) ⇒ Object


1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
# File 'lib/rant/archive/rubyzip.rb', line 1521

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


1555
1556
1557
# File 'lib/rant/archive/rubyzip.rb', line 1555

def local_length
  to_local_bin.length
end

#merge(binstr) ⇒ Object


1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
# File 'lib/rant/archive/rubyzip.rb', line 1488

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


1544
1545
1546
1547
1548
1549
1550
# File 'lib/rant/archive/rubyzip.rb', line 1544

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


1535
1536
1537
1538
1539
1540
1541
# File 'lib/rant/archive/rubyzip.rb', line 1535

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