Class: Zip::ZipExtraField::UniversalTime

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

Overview

Info-ZIP Additional timestamp field

Constant Summary

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

- (UniversalTime) initialize(binstr = nil)



1710
1711
1712
1713
1714
1715
1716
# File 'lib/zip/zip.rb', line 1710

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

Instance Attribute Details

- (Object) atime

Returns the value of attribute atime



1717
1718
1719
# File 'lib/zip/zip.rb', line 1717

def atime
  @atime
end

- (Object) ctime

Returns the value of attribute ctime



1717
1718
1719
# File 'lib/zip/zip.rb', line 1717

def ctime
  @ctime
end

- (Object) flag

Returns the value of attribute flag



1717
1718
1719
# File 'lib/zip/zip.rb', line 1717

def flag
  @flag
end

- (Object) mtime

Returns the value of attribute mtime



1717
1718
1719
# File 'lib/zip/zip.rb', line 1717

def mtime
  @mtime
end

Instance Method Details

- (Object) ==(other)



1729
1730
1731
1732
1733
# File 'lib/zip/zip.rb', line 1729

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

- (Object) merge(binstr)



1719
1720
1721
1722
1723
1724
1725
1726
1727
# File 'lib/zip/zip.rb', line 1719

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

- (Object) pack_for_c_dir



1743
1744
1745
1746
1747
# File 'lib/zip/zip.rb', line 1743

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

- (Object) pack_for_local



1735
1736
1737
1738
1739
1740
1741
# File 'lib/zip/zip.rb', line 1735

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