Class: Archive::Zip::ExtraField::Raw

Inherits:
Object
  • Object
show all
Defined in:
lib/archive/zip/extra_field/raw.rb

Overview

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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header_id, data, central_record) ⇒ Raw

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.


32
33
34
35
36
37
38
39
40
41
# File 'lib/archive/zip/extra_field/raw.rb', line 32

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

Instance Attribute Details

#central_record_dataObject (readonly)

Returns the data contained within this ExtraField.


46
47
48
# File 'lib/archive/zip/extra_field/raw.rb', line 46

def central_record_data
  @central_record_data
end

#header_idObject (readonly)

Returns the header ID for this ExtraField.


44
45
46
# File 'lib/archive/zip/extra_field/raw.rb', line 44

def header_id
  @header_id
end

#local_record_dataObject (readonly)

Returns the value of attribute local_record_data


47
48
49
# File 'lib/archive/zip/extra_field/raw.rb', line 47

def local_record_data
  @local_record_data
end

Class Method Details

.parse_central(header_id, data) ⇒ Object

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


15
16
17
# File 'lib/archive/zip/extra_field/raw.rb', line 15

def parse_central(header_id, data)
  new(header_id, data, true)
end

.parse_local(header_id, data) ⇒ Object

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


22
23
24
# File 'lib/archive/zip/extra_field/raw.rb', line 22

def parse_local(header_id, data)
  new(header_id, data, false)
end

Instance Method Details

#dump_centralObject

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.


73
74
75
76
77
# File 'lib/archive/zip/extra_field/raw.rb', line 73

def dump_central
  @central_record_data.collect do |data|
    [header_id, data.size].pack('vv') + data
  end
end

#dump_localObject

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.


84
85
86
87
88
# File 'lib/archive/zip/extra_field/raw.rb', line 84

def dump_local
  @local_record_data.collect do |data|
    [header_id, data.size].pack('vv') + data
  end
end

#merge(other) ⇒ Object

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.


56
57
58
59
60
61
62
63
64
65
66
# File 'lib/archive/zip/extra_field/raw.rb', line 56

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