Class: Rant::Archive::Rubyzip::ZipExtraField::UniversalTime

Inherits:
Generic
  • Object
show all
Defined in:
lib/rant/archive/rubyzip.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.


1407
1408
1409
1410
1411
1412
1413
# File 'lib/rant/archive/rubyzip.rb', line 1407

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


1414
1415
1416
# File 'lib/rant/archive/rubyzip.rb', line 1414

def atime
  @atime
end

#ctimeObject

Returns the value of attribute ctime


1414
1415
1416
# File 'lib/rant/archive/rubyzip.rb', line 1414

def ctime
  @ctime
end

#flagObject

Returns the value of attribute flag


1414
1415
1416
# File 'lib/rant/archive/rubyzip.rb', line 1414

def flag
  @flag
end

#mtimeObject

Returns the value of attribute mtime


1414
1415
1416
# File 'lib/rant/archive/rubyzip.rb', line 1414

def mtime
  @mtime
end

Instance Method Details

#==(other) ⇒ Object


1426
1427
1428
1429
1430
# File 'lib/rant/archive/rubyzip.rb', line 1426

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

#merge(binstr) ⇒ Object


1416
1417
1418
1419
1420
1421
1422
1423
1424
# File 'lib/rant/archive/rubyzip.rb', line 1416

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

#pack_for_c_dirObject


1440
1441
1442
1443
1444
# File 'lib/rant/archive/rubyzip.rb', line 1440

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

#pack_for_localObject


1432
1433
1434
1435
1436
1437
1438
# File 'lib/rant/archive/rubyzip.rb', line 1432

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