Class: Archive::Zip::ExtraField::Unix
- Inherits:
-
Object
- Object
- Archive::Zip::ExtraField::Unix
- Defined in:
- lib/archive/zip/extra_field/unix.rb
Overview
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.
Constant Summary collapse
- ID =
The identifier reserved for this extra field type.
0x000d
Instance Attribute Summary collapse
-
#atime ⇒ Object
A Time object representing the last accessed time for an entry.
-
#data ⇒ Object
readonly
protected
Returns the value of attribute data.
-
#gid ⇒ Object
An integer representing the group ownership for an entry.
-
#header_id ⇒ Object
readonly
Returns the header ID for this ExtraField.
-
#mtime ⇒ Object
A Time object representing the last modified time for an entry.
-
#uid ⇒ Object
An integer representing the user ownership for an entry.
Class Method Summary collapse
-
.parse_central(data) ⇒ Object
(also: parse_local)
This method signature is part of the interface contract expected by Archive::Zip::Entry for extra field objects.
Instance Method Summary collapse
-
#device_numbers ⇒ Object
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.
-
#device_numbers=(major_minor) ⇒ Object
Takes a two element array containing major and minor device numbers and stores the numbers into the variable data section of this object.
-
#dump_local ⇒ Object
(also: #dump_central)
This method signature is part of the interface contract expected by Archive::Zip::Entry for extra field objects.
-
#initialize(mtime, atime, uid, gid, data = '') ⇒ Unix
constructor
Creates a new instance of this class.
-
#link_target ⇒ Object
Attempts to return a string representing the path of a file which is either a symlink or hard link target which may be stored in the variable data section of this object.
-
#link_target=(link_target) ⇒ Object
Takes a string containing the path to a file which is either a symlink or a hardlink target and stores it in the variable data section of this object.
-
#merge(other) ⇒ Object
This method signature is part of the interface contract expected by Archive::Zip::Entry for extra field objects.
Constructor Details
#initialize(mtime, atime, uid, gid, data = '') ⇒ Unix
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.
46 47 48 49 50 51 52 53 |
# File 'lib/archive/zip/extra_field/unix.rb', line 46 def initialize(mtime, atime, uid, gid, data = '') @header_id = ID @mtime = mtime @atime = atime @uid = uid @gid = gid @data = data end |
Instance Attribute Details
#atime ⇒ Object
A Time object representing the last accessed time for an entry.
58 59 60 |
# File 'lib/archive/zip/extra_field/unix.rb', line 58 def atime @atime end |
#data ⇒ Object (readonly, protected)
Returns the value of attribute data.
138 139 140 |
# File 'lib/archive/zip/extra_field/unix.rb', line 138 def data @data end |
#gid ⇒ Object
An integer representing the group ownership for an entry.
64 65 66 |
# File 'lib/archive/zip/extra_field/unix.rb', line 64 def gid @gid end |
#header_id ⇒ Object (readonly)
Returns the header ID for this ExtraField.
56 57 58 |
# File 'lib/archive/zip/extra_field/unix.rb', line 56 def header_id @header_id end |
#mtime ⇒ Object
A Time object representing the last modified time for an entry.
60 61 62 |
# File 'lib/archive/zip/extra_field/unix.rb', line 60 def mtime @mtime end |
#uid ⇒ Object
An integer representing the user ownership for an entry.
62 63 64 |
# File 'lib/archive/zip/extra_field/unix.rb', line 62 def uid @uid end |
Class Method Details
.parse_central(data) ⇒ Object Also known as: parse_local
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.
30 31 32 33 34 35 36 |
# File 'lib/archive/zip/extra_field/unix.rb', line 30 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 |
Instance Method Details
#device_numbers ⇒ Object
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.
69 70 71 |
# File 'lib/archive/zip/extra_field/unix.rb', line 69 def device_numbers @data.unpack('VV') end |
#device_numbers=(major_minor) ⇒ Object
Takes a two element array containing major and minor device numbers and stores the numbers into the variable data section of this object.
75 76 77 |
# File 'lib/archive/zip/extra_field/unix.rb', line 75 def device_numbers=(major_minor) @data = major_minor.pack('VV') end |
#dump_local ⇒ Object Also known as: dump_central
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.
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/archive/zip/extra_field/unix.rb', line 118 def dump_local [ ID, 12 + @data.size, @atime.to_i, @mtime.to_i, @uid, @gid ].pack('vvVVvv') + @data end |
#link_target ⇒ Object
Attempts to return a string representing the path of a file which is either a symlink or hard link target which may be stored in the variable data section of this object.
82 83 84 |
# File 'lib/archive/zip/extra_field/unix.rb', line 82 def link_target @data end |
#link_target=(link_target) ⇒ Object
Takes a string containing the path to a file which is either a symlink or a hardlink target and stores it in the variable data section of this object.
89 90 91 |
# File 'lib/archive/zip/extra_field/unix.rb', line 89 def link_target=(link_target) @data = link_target 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 is not the same class as this object.
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/archive/zip/extra_field/unix.rb', line 99 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 |