Parent

Archive::Zip::ExtraField::Raw

Archive::Zip::Entry::ExtraField::Raw represents an unknown extra field. It is used to store extra fields the Archive::Zip library does not directly support.

Do not use this class directly. Define a new class which supports the extra field of interest directly instead.

Attributes

central_record_data[R]

Returns the data contained within this ExtraField.

header_id[R]

Returns the header ID for this ExtraField.

local_record_data[R]

Public Class Methods

new(header_id, data, central_record) click to toggle source

Simply stores header_id and data for later reproduction by dump_central or dump_local. central_record indicates that this field resides in the central file record for an entry when true. When false, it indicates that this field resides in the local file record for an entry.

# File lib/archive/zip/extra_field/raw.rb, line 31
def initialize(header_id, data, central_record)
  @header_id = header_id
  @central_record_data = []
  @local_record_data = []
  if central_record then
    @central_record_data << data
  else
    @local_record_data << data
  end
end
parse_central(header_id, data) click to toggle source

Simply stores header_id and data for later reproduction by dump_central. This is essentially and alias for new.

# File lib/archive/zip/extra_field/raw.rb, line 14
def parse_central(header_id, data)
  new(header_id, data, true)
end
parse_local(header_id, data) click to toggle source

Simply stores header_id and data for later reproduction by dump_local. This is essentially and alias for new.

# File lib/archive/zip/extra_field/raw.rb, line 21
def parse_local(header_id, data)
  new(header_id, data, false)
end

Public Instance Methods

dump_central() click to toggle source

This method signature is part of the interface contract expected by Archive::Zip::Entry for extra field objects.

Returns a String suitable to writing to a central file record in a ZIP archive file which contains the data for this object.

# File lib/archive/zip/extra_field/raw.rb, line 72
def dump_central
  @central_record_data.collect do |data|
    [header_id, data.size].pack('vv') + data
  end
end
dump_local() click to toggle source

This method signature is part of the interface contract expected by Archive::Zip::Entry for extra field objects.

Returns a String suitable to writing to a local file record in a ZIP archive file which contains the data for this object.

# File lib/archive/zip/extra_field/raw.rb, line 83
def dump_local
  @local_record_data.collect do |data|
    [header_id, data.size].pack('vv') + data
  end
end
merge(other) click to toggle source

This method signature is part of the interface contract expected by Archive::Zip::Entry for extra field objects.

Merges the attributes of other into this object and returns self.

Raises ArgumentError if other does not have the same header ID as this object.

# File lib/archive/zip/extra_field/raw.rb, line 55
def merge(other)
  if header_id != other.header_id then
    raise ArgumentError,
      "Header ID mismatch: #{header_id} != #{other.header_id}"
  end

  @central_record_data += other.central_record_data
  @local_record_data += other.local_record_data

  self
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.