Class: Zip::ZipExtraField::IUnix

Inherits:
Generic
  • Object
show all
Defined in:
lib/zip/zip_extra_field.rb

Overview

Info-ZIP Extra for UNIX uid/gid

Constant Summary collapse

HEADER_ID =
"Ux"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Generic

#initial_parse, name, register_map, #to_c_dir_bin, #to_local_bin

Constructor Details

#initialize(binstr = nil) ⇒ IUnix

Returns a new instance of IUnix.



98
99
100
101
102
# File 'lib/zip/zip_extra_field.rb', line 98

def initialize(binstr = nil)
  @uid = 0
  @gid = 0
  binstr and merge(binstr)
end

Instance Attribute Details

#gidObject

Returns the value of attribute gid.



103
104
105
# File 'lib/zip/zip_extra_field.rb', line 103

def gid
  @gid
end

#uidObject

Returns the value of attribute uid.



103
104
105
# File 'lib/zip/zip_extra_field.rb', line 103

def uid
  @uid
end

Instance Method Details

#==(other) ⇒ Object



115
116
117
118
# File 'lib/zip/zip_extra_field.rb', line 115

def ==(other)
  @uid == other.uid &&
  @gid == other.gid
end

#merge(binstr) ⇒ Object



105
106
107
108
109
110
111
112
113
# File 'lib/zip/zip_extra_field.rb', line 105

def merge(binstr)
  return if binstr.empty?
  size, content = initial_parse(binstr)
  # size: 0 for central directory. 4 for local header
  return if(!size || size == 0)
  uid, gid = content.unpack("vv")
  @uid ||= uid
  @gid ||= gid
end

#pack_for_c_dirObject



124
125
126
# File 'lib/zip/zip_extra_field.rb', line 124

def pack_for_c_dir
  ""
end

#pack_for_localObject



120
121
122
# File 'lib/zip/zip_extra_field.rb', line 120

def pack_for_local
  [@uid, @gid].pack("vv")
end