Class: Zip::ExtraField::NTFS

Inherits:
Generic
  • Object
show all
Defined in:
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 =
10_000_000.0
SEC_TO_UNIX_EPOCH =
11_644_473_600

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/zip/extra_field/ntfs.rb', line 11

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

Instance Attribute Details

#atimeObject

Returns the value of attribute atime.



18
19
20
# File 'lib/zip/extra_field/ntfs.rb', line 18

def atime
  @atime
end

#ctimeObject

Returns the value of attribute ctime.



18
19
20
# File 'lib/zip/extra_field/ntfs.rb', line 18

def ctime
  @ctime
end

#mtimeObject

Returns the value of attribute mtime.



18
19
20
# File 'lib/zip/extra_field/ntfs.rb', line 18

def mtime
  @mtime
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
41
42
# File 'lib/zip/extra_field/ntfs.rb', line 38

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
36
# File 'lib/zip/extra_field/ntfs.rb', line 20

def merge(binstr)
  return if binstr.empty?

  size, content = initial_parse(binstr)
  (size && content) || return

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

  tag1 = tags[1]
  return unless tag1

  ntfs_mtime, ntfs_atime, ntfs_ctime = tag1.unpack('Q<Q<Q<')
  ntfs_mtime && @mtime ||= from_ntfs_time(ntfs_mtime)
  ntfs_atime && @atime ||= from_ntfs_time(ntfs_atime)
  ntfs_ctime && @ctime ||= from_ntfs_time(ntfs_ctime)
end

#pack_for_c_dirObject

But 7-zip for Windows only stores at central dir



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/zip/extra_field/ntfs.rb', line 50

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<')
      tag1 << [to_ntfs_time(@ctime)].pack('Q<') if @ctime
    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



45
46
47
# File 'lib/zip/extra_field/ntfs.rb', line 45

def pack_for_local
  pack_for_c_dir
end