Class: Zip::ExtraField::IUnix

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

Overview

Info-ZIP Extra for UNIX uid/gid

Constant Summary collapse

HEADER_ID =

:nodoc:

'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.



9
10
11
12
13
# File 'lib/zip/extra_field/unix.rb', line 9

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

Instance Attribute Details

#gidObject

Returns the value of attribute gid.



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

def gid
  @gid
end

#uidObject

Returns the value of attribute uid.



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

def uid
  @uid
end

Instance Method Details

#==(other) ⇒ Object



29
30
31
# File 'lib/zip/extra_field/unix.rb', line 29

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

#merge(binstr) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/zip/extra_field/unix.rb', line 17

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



37
38
39
# File 'lib/zip/extra_field/unix.rb', line 37

def pack_for_c_dir
  ''
end

#pack_for_localObject



33
34
35
# File 'lib/zip/extra_field/unix.rb', line 33

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