Class: Zip::ExtraField::NTFS

Inherits:
Generic
  • Object
show all
Defined in:
lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/ntfs.rb

Overview

PKWARE NTFS Extra Field (0x000a) Only Tag 0x0001 is supported

Constant Summary collapse

HEADER_ID =
[0x000A].pack('v')
WINDOWS_TICK =
10000000.0
SEC_TO_UNIX_EPOCH =
11644473600

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

Returns a new instance of NTFS.



11
12
13
14
15
16
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/ntfs.rb', line 11

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

Instance Attribute Details

#atimeObject

Returns the value of attribute atime.



18
19
20
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/ntfs.rb', line 18

def atime
  @atime
end

#ctimeObject

Returns the value of attribute ctime.



18
19
20
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/ntfs.rb', line 18

def ctime
  @ctime
end

#mtimeObject

Returns the value of attribute mtime.



18
19
20
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/ntfs.rb', line 18

def mtime
  @mtime
end

Instance Method Details

#==(other) ⇒ Object



37
38
39
40
41
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/ntfs.rb', line 37

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

#merge(binstr) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/ntfs.rb', line 20

def merge(binstr)
  return if binstr.empty?
  size, content = initial_parse(binstr)
  (size && content) or return

  content = content[4..-1]
  tags = parse_tags(content)

  tag1 = tags[1]
  if tag1
    ntfs_mtime, ntfs_atime, ntfs_ctime = tag1.unpack("Q<Q<Q<")
    ntfs_mtime and @mtime ||= from_ntfs_time(ntfs_mtime)
    ntfs_atime and @atime ||= from_ntfs_time(ntfs_atime)
    ntfs_ctime and @ctime ||= from_ntfs_time(ntfs_ctime)
  end
end

#pack_for_c_dirObject

But 7-zip for Windows only stores at central dir



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/ntfs.rb', line 49

def pack_for_c_dir
  # reserved 0 and tag 1
  s = [0, 1].pack("Vv")

  tag1 = ''.force_encoding(Encoding::BINARY)
  if @mtime
    tag1 << [to_ntfs_time(@mtime)].pack('Q<')
    if @atime
      tag1 << [to_ntfs_time(@atime)].pack('Q<')
      if @ctime
        tag1 << [to_ntfs_time(@ctime)].pack('Q<')
      end
    end
  end
  s << [tag1.bytesize].pack('v') << tag1
  s
end

#pack_for_localObject

Info-ZIP note states this extra field is stored at local header



44
45
46
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/ntfs.rb', line 44

def pack_for_local
  pack_for_c_dir
end