Class: Omnizip::Formats::Tar::Entry

Inherits:
Object
  • Object
show all
Includes:
Entry, Constants
Defined in:
lib/omnizip/formats/tar/entry.rb

Overview

TAR entry model

Represents a single entry (file, directory, link) in a TAR archive

Constant Summary

Constants included from Constants

Constants::BLOCK_SIZE, Constants::CHECKSUM_OFFSET, Constants::CHECKSUM_SIZE, Constants::DEVMAJOR_OFFSET, Constants::DEVMAJOR_SIZE, Constants::DEVMINOR_OFFSET, Constants::DEVMINOR_SIZE, Constants::GID_OFFSET, Constants::GID_SIZE, Constants::GNAME_OFFSET, Constants::GNAME_SIZE, Constants::HEADER_SIZE, Constants::LINKNAME_OFFSET, Constants::LINKNAME_SIZE, Constants::MAGIC_OFFSET, Constants::MAGIC_SIZE, Constants::MAX_FILE_SIZE, Constants::MODE_OFFSET, Constants::MODE_SIZE, Constants::MTIME_OFFSET, Constants::MTIME_SIZE, Constants::NAME_OFFSET, Constants::NAME_SIZE, Constants::PREFIX_OFFSET, Constants::PREFIX_SIZE, Constants::SIZE_OFFSET, Constants::SIZE_SIZE, Constants::TYPEFLAG_OFFSET, Constants::TYPEFLAG_SIZE, Constants::TYPE_BLOCK_DEVICE, Constants::TYPE_CHAR_DEVICE, Constants::TYPE_CONTIGUOUS, Constants::TYPE_DIRECTORY, Constants::TYPE_EXTENDED, Constants::TYPE_FIFO, Constants::TYPE_GLOBAL_EXTENDED, Constants::TYPE_GNU_LONGLINK, Constants::TYPE_GNU_LONGNAME, Constants::TYPE_HARD_LINK, Constants::TYPE_REGULAR, Constants::TYPE_SYMLINK, Constants::UID_OFFSET, Constants::UID_SIZE, Constants::UNAME_OFFSET, Constants::UNAME_SIZE, Constants::USTAR_MAGIC, Constants::USTAR_VERSION, Constants::VERSION_OFFSET, Constants::VERSION_SIZE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Entry

Initialize a new TAR entry

Parameters:

  • name (String)

    Entry name/path

  • options (Hash) (defaults to: {})

    Entry options



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/omnizip/formats/tar/entry.rb', line 26

def initialize(name, options = {})
  @name = name
  @mode = options[:mode] || 0o644
  @uid = options[:uid] || 0
  @gid = options[:gid] || 0
  @size = options[:size] || 0
  @mtime = options[:mtime] || Time.now
  @typeflag = options[:typeflag] || TYPE_REGULAR
  @linkname = options[:linkname] || ""
  @uname = options[:uname] || ""
  @gname = options[:gname] || ""
  @devmajor = options[:devmajor] || 0
  @devminor = options[:devminor] || 0
  @prefix = options[:prefix] || ""
  @data = nil
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



15
16
17
# File 'lib/omnizip/formats/tar/entry.rb', line 15

def data
  @data
end

#devmajorObject

Returns the value of attribute devmajor.



13
14
15
# File 'lib/omnizip/formats/tar/entry.rb', line 13

def devmajor
  @devmajor
end

#devminorObject

Returns the value of attribute devminor.



13
14
15
# File 'lib/omnizip/formats/tar/entry.rb', line 13

def devminor
  @devminor
end

#gidObject

Returns the value of attribute gid.



13
14
15
# File 'lib/omnizip/formats/tar/entry.rb', line 13

def gid
  @gid
end

#gnameObject

Returns the value of attribute gname.



13
14
15
# File 'lib/omnizip/formats/tar/entry.rb', line 13

def gname
  @gname
end

#linknameObject

Returns the value of attribute linkname.



13
14
15
# File 'lib/omnizip/formats/tar/entry.rb', line 13

def linkname
  @linkname
end

#modeObject

Returns the value of attribute mode.



13
14
15
# File 'lib/omnizip/formats/tar/entry.rb', line 13

def mode
  @mode
end

#mtimeObject

Returns the value of attribute mtime.



13
14
15
# File 'lib/omnizip/formats/tar/entry.rb', line 13

def mtime
  @mtime
end

#nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/omnizip/formats/tar/entry.rb', line 13

def name
  @name
end

#prefixObject

Returns the value of attribute prefix.



13
14
15
# File 'lib/omnizip/formats/tar/entry.rb', line 13

def prefix
  @prefix
end

#sizeObject

Returns the value of attribute size.



13
14
15
# File 'lib/omnizip/formats/tar/entry.rb', line 13

def size
  @size
end

#typeflagObject

Returns the value of attribute typeflag.



13
14
15
# File 'lib/omnizip/formats/tar/entry.rb', line 13

def typeflag
  @typeflag
end

#uidObject

Returns the value of attribute uid.



13
14
15
# File 'lib/omnizip/formats/tar/entry.rb', line 13

def uid
  @uid
end

#unameObject

Returns the value of attribute uname.



13
14
15
# File 'lib/omnizip/formats/tar/entry.rb', line 13

def uname
  @uname
end

Class Method Details

.calculate_checksum(header) ⇒ Integer

Calculate checksum for TAR header

Parameters:

  • header (String)

    TAR header bytes

Returns:

  • (Integer)

    Checksum value



87
88
89
90
91
92
93
94
# File 'lib/omnizip/formats/tar/entry.rb', line 87

def self.calculate_checksum(header)
  # Replace checksum field with spaces for calculation
  checksum_header = header.dup
  checksum_header[CHECKSUM_OFFSET, CHECKSUM_SIZE] = " " * CHECKSUM_SIZE

  # Sum all bytes
  checksum_header.bytes.sum
end

Instance Method Details

#directory?Boolean

Check if entry is a directory

Returns:

  • (Boolean)

    true if directory



54
55
56
# File 'lib/omnizip/formats/tar/entry.rb', line 54

def directory?
  @typeflag == TYPE_DIRECTORY
end

#entry_directory?Boolean

Returns:

  • (Boolean)


18
# File 'lib/omnizip/formats/tar/entry.rb', line 18

def entry_directory? = directory?

#entry_mtimeObject



20
# File 'lib/omnizip/formats/tar/entry.rb', line 20

def entry_mtime = mtime

#entry_nameObject



17
# File 'lib/omnizip/formats/tar/entry.rb', line 17

def entry_name = name

#entry_sizeObject



19
# File 'lib/omnizip/formats/tar/entry.rb', line 19

def entry_size = size

#file?Boolean

Check if entry is a file

Returns:

  • (Boolean)

    true if regular file



61
62
63
# File 'lib/omnizip/formats/tar/entry.rb', line 61

def file?
  @typeflag == TYPE_REGULAR || @typeflag.nil? || @typeflag.empty?
end

#full_nameString

Get full entry name (prefix + name)

Returns:

  • (String)

    Full entry name



75
76
77
78
79
80
81
# File 'lib/omnizip/formats/tar/entry.rb', line 75

def full_name
  if @prefix && !@prefix.empty?
    File.join(@prefix, @name)
  else
    @name
  end
end

#symlink?Boolean

Check if entry is a symbolic link

Returns:

  • (Boolean)

    true if symbolic link



68
69
70
# File 'lib/omnizip/formats/tar/entry.rb', line 68

def symlink?
  @typeflag == TYPE_SYMLINK
end