Parent

Archive::Zip::ExtraField::Unix

Archive::Zip::Entry::ExtraField::Unix represents an extra field which contains the last modified time, last accessed time, user name, and group name for a ZIP archive entry. Times are in Unix time format (seconds since the epoc).

This class also optionally stores either major and minor numbers for devices or a link target for either hard or soft links. Which is in use when given and instance of this class depends upon the external file attributes for the ZIP archive entry associated with this extra field.

Constants

ID

The identifier reserved for this extra field type.

Attributes

atime[RW]

A Time object representing the last accessed time for an entry.

data[R]
gid[RW]

An integer representing the group ownership for an entry.

header_id[R]

Returns the header ID for this ExtraField.

mtime[RW]

A Time object representing the last modified time for an entry.

uid[RW]

An integer representing the user ownership for an entry.

Public Class Methods

new(mtime, atime, uid, gid, data = '') click to toggle source

Creates a new instance of this class. mtime and atime should be Time instances. uid and gid should be user and group IDs as Integers respectively. data should be a string containing either major and minor device numbers consecutively packed as little endian, 4-byte, unsigned integers (see the V directive of Array#pack) or a path to use as a link target.

# File lib/archive/zip/extra_field/unix.rb, line 45
def initialize(mtime, atime, uid, gid, data = '')
  @header_id = ID
  @mtime = mtime
  @atime = atime
  @uid = uid
  @gid = gid
  @data = data
end
parse_central(data) click to toggle source

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

Parses data which is expected to be a String formatted according to the official ZIP specification.

Raises Archive::Zip::ExtraFieldError if data contains invalid data.

# File lib/archive/zip/extra_field/unix.rb, line 29
def parse_central(data)
  unless data.length >= 12 then
    raise Zip::ExtraFieldError, "invalid size for Unix data: #{data.size}"
  end
  atime, mtime, uid, gid, rest = data.unpack('VVvva')
  new(Time.at(mtime), Time.at(atime), uid, gid, rest)
end
Also aliased as: parse_local
parse_local(data) click to toggle source
Alias for: parse_central

Public Instance Methods

device_numbers() click to toggle source

Attempts to return a two element array representing the major and minor device numbers which may be stored in the variable data section of this object.

# File lib/archive/zip/extra_field/unix.rb, line 68
def device_numbers
  @data.unpack('VV')
end
device_numbers=(major_minor) click to toggle source

Takes a two element array containing major and minor device numbers and stores the numbers into the variable data section of this object.

# File lib/archive/zip/extra_field/unix.rb, line 74
def device_numbers=(major_minor)
  @data = major_minor.pack('VV')
end
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/unix.rb, line 117
def dump_central
  ''
end
Also aliased as: dump_local
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/unix.rb, line 126
def dump_local
  [
    ID,
    12 + @data.size,
    @atime.to_i,
    @mtime.to_i,
    @uid,
    @gid
  ].pack('vvVVvv') + @data
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 is not the same class as this object.

# File lib/archive/zip/extra_field/unix.rb, line 98
def merge(other)
  if self.class != other.class then
    raise ArgumentError, "#{self.class} is not the same as #{other.class}"
  end

  @atime = other.atime
  @mtime = other.mtime
  @uid = other.uid
  @gid = other.gid
  @data = other.data

  self
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.