Class: Zip::ZipExtraField::UniversalTime

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

Overview

Info-ZIP Additional timestamp field

Constant Summary collapse

HEADER_ID =
"UT"

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

Returns a new instance of UniversalTime.



53
54
55
56
57
58
59
# File 'lib/zip/zip_extra_field.rb', line 53

def initialize(binstr = nil)
  @ctime = nil
  @mtime = nil
  @atime = nil
  @flag  = nil
  binstr and merge(binstr)
end

Instance Attribute Details

#atimeObject

Returns the value of attribute atime.



60
61
62
# File 'lib/zip/zip_extra_field.rb', line 60

def atime
  @atime
end

#ctimeObject

Returns the value of attribute ctime.



60
61
62
# File 'lib/zip/zip_extra_field.rb', line 60

def ctime
  @ctime
end

#flagObject

Returns the value of attribute flag.



60
61
62
# File 'lib/zip/zip_extra_field.rb', line 60

def flag
  @flag
end

#mtimeObject

Returns the value of attribute mtime.



60
61
62
# File 'lib/zip/zip_extra_field.rb', line 60

def mtime
  @mtime
end

Instance Method Details

#==(other) ⇒ Object



72
73
74
75
76
# File 'lib/zip/zip_extra_field.rb', line 72

def ==(other)
  @mtime == other.mtime &&
  @atime == other.atime &&
  @ctime == other.ctime
end

#merge(binstr) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/zip/zip_extra_field.rb', line 62

def merge(binstr)
  return if binstr.empty?
  size, content = initial_parse(binstr)
  size or return
  @flag, mtime, atime, ctime = content.unpack("CVVV")
  mtime and @mtime ||= DOSTime.at(mtime)
  atime and @atime ||= DOSTime.at(atime)
  ctime and @ctime ||= DOSTime.at(ctime)
end

#pack_for_c_dirObject



86
87
88
89
90
# File 'lib/zip/zip_extra_field.rb', line 86

def pack_for_c_dir
  s = [@flag].pack("C")
  @flag & 1 == 1 and s << [@mtime.to_i].pack("V")
  s
end

#pack_for_localObject



78
79
80
81
82
83
84
# File 'lib/zip/zip_extra_field.rb', line 78

def pack_for_local
  s = [@flag].pack("C")
  @flag & 1 != 0 and s << [@mtime.to_i].pack("V")
  @flag & 2 != 0 and s << [@atime.to_i].pack("V")
  @flag & 4 != 0 and s << [@ctime.to_i].pack("V")
  s
end