Class: Zip::ExtraField::OldUnix

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

Overview

Olf Info-ZIP Extra for UNIX uid/gid and file timestampes

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) ⇒ OldUnix

Returns a new instance of OldUnix.



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

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

Instance Attribute Details

#atimeObject

Returns the value of attribute atime.



17
18
19
# File 'lib/zip/extra_field/old_unix.rb', line 17

def atime
  @atime
end

#gidObject

Returns the value of attribute gid.



17
18
19
# File 'lib/zip/extra_field/old_unix.rb', line 17

def gid
  @gid
end

#mtimeObject

Returns the value of attribute mtime.



17
18
19
# File 'lib/zip/extra_field/old_unix.rb', line 17

def mtime
  @mtime
end

#uidObject

Returns the value of attribute uid.



17
18
19
# File 'lib/zip/extra_field/old_unix.rb', line 17

def uid
  @uid
end

Instance Method Details

#==(other) ⇒ Object



33
34
35
36
37
38
# File 'lib/zip/extra_field/old_unix.rb', line 33

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

#merge(binstr) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/zip/extra_field/old_unix.rb', line 19

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

  atime, mtime, uid, gid = content.unpack('VVvv')
  @uid ||= uid
  @gid ||= gid
  @atime ||= atime
  @mtime ||= mtime # rubocop:disable Naming/MemoizedInstanceVariableName
end

#pack_for_c_dirObject



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

def pack_for_c_dir
  [@atime, @mtime].pack('VV')
end

#pack_for_localObject



40
41
42
# File 'lib/zip/extra_field/old_unix.rb', line 40

def pack_for_local
  [@atime, @mtime, @uid, @gid].pack('VVvv')
end