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 =

:nodoc:

[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.



13
14
15
16
17
18
# File 'lib/zip/extra_field/ntfs.rb', line 13

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

Instance Attribute Details

#atimeObject

Returns the value of attribute atime.



20
21
22
# File 'lib/zip/extra_field/ntfs.rb', line 20

def atime
  @atime
end

#ctimeObject

Returns the value of attribute ctime.



20
21
22
# File 'lib/zip/extra_field/ntfs.rb', line 20

def ctime
  @ctime
end

#mtimeObject

Returns the value of attribute mtime.



20
21
22
# File 'lib/zip/extra_field/ntfs.rb', line 20

def mtime
  @mtime
end

Instance Method Details

#==(other) ⇒ Object



40
41
42
43
44
# File 'lib/zip/extra_field/ntfs.rb', line 40

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

#merge(binstr) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/zip/extra_field/ntfs.rb', line 22

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



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

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



47
48
49
# File 'lib/zip/extra_field/ntfs.rb', line 47

def pack_for_local
  pack_for_c_dir
end