Class: Omnizip::Formats::Tar::Entry
- Inherits:
-
Object
- Object
- Omnizip::Formats::Tar::Entry
- Includes:
- 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
-
#data ⇒ Object
Returns the value of attribute data.
-
#devmajor ⇒ Object
Returns the value of attribute devmajor.
-
#devminor ⇒ Object
Returns the value of attribute devminor.
-
#gid ⇒ Object
Returns the value of attribute gid.
-
#gname ⇒ Object
Returns the value of attribute gname.
-
#linkname ⇒ Object
Returns the value of attribute linkname.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#mtime ⇒ Object
Returns the value of attribute mtime.
-
#name ⇒ Object
Returns the value of attribute name.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#size ⇒ Object
Returns the value of attribute size.
-
#typeflag ⇒ Object
Returns the value of attribute typeflag.
-
#uid ⇒ Object
Returns the value of attribute uid.
-
#uname ⇒ Object
Returns the value of attribute uname.
Class Method Summary collapse
-
.calculate_checksum(header) ⇒ Integer
Calculate checksum for TAR header.
Instance Method Summary collapse
-
#directory? ⇒ Boolean
Check if entry is a directory.
-
#file? ⇒ Boolean
Check if entry is a file.
-
#full_name ⇒ String
Get full entry name (prefix + name).
-
#initialize(name, options = {}) ⇒ Entry
constructor
Initialize a new TAR entry.
-
#symlink? ⇒ Boolean
Check if entry is a symbolic link.
Constructor Details
#initialize(name, options = {}) ⇒ Entry
Initialize a new TAR entry
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/omnizip/formats/tar/entry.rb', line 20 def initialize(name, = {}) @name = name @mode = [:mode] || 0o644 @uid = [:uid] || 0 @gid = [:gid] || 0 @size = [:size] || 0 @mtime = [:mtime] || Time.now @typeflag = [:typeflag] || TYPE_REGULAR @linkname = [:linkname] || "" @uname = [:uname] || "" @gname = [:gname] || "" @devmajor = [:devmajor] || 0 @devminor = [:devminor] || 0 @prefix = [:prefix] || "" @data = nil end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
14 15 16 |
# File 'lib/omnizip/formats/tar/entry.rb', line 14 def data @data end |
#devmajor ⇒ Object
Returns the value of attribute devmajor.
12 13 14 |
# File 'lib/omnizip/formats/tar/entry.rb', line 12 def devmajor @devmajor end |
#devminor ⇒ Object
Returns the value of attribute devminor.
12 13 14 |
# File 'lib/omnizip/formats/tar/entry.rb', line 12 def devminor @devminor end |
#gid ⇒ Object
Returns the value of attribute gid.
12 13 14 |
# File 'lib/omnizip/formats/tar/entry.rb', line 12 def gid @gid end |
#gname ⇒ Object
Returns the value of attribute gname.
12 13 14 |
# File 'lib/omnizip/formats/tar/entry.rb', line 12 def gname @gname end |
#linkname ⇒ Object
Returns the value of attribute linkname.
12 13 14 |
# File 'lib/omnizip/formats/tar/entry.rb', line 12 def linkname @linkname end |
#mode ⇒ Object
Returns the value of attribute mode.
12 13 14 |
# File 'lib/omnizip/formats/tar/entry.rb', line 12 def mode @mode end |
#mtime ⇒ Object
Returns the value of attribute mtime.
12 13 14 |
# File 'lib/omnizip/formats/tar/entry.rb', line 12 def mtime @mtime end |
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'lib/omnizip/formats/tar/entry.rb', line 12 def name @name end |
#prefix ⇒ Object
Returns the value of attribute prefix.
12 13 14 |
# File 'lib/omnizip/formats/tar/entry.rb', line 12 def prefix @prefix end |
#size ⇒ Object
Returns the value of attribute size.
12 13 14 |
# File 'lib/omnizip/formats/tar/entry.rb', line 12 def size @size end |
#typeflag ⇒ Object
Returns the value of attribute typeflag.
12 13 14 |
# File 'lib/omnizip/formats/tar/entry.rb', line 12 def typeflag @typeflag end |
#uid ⇒ Object
Returns the value of attribute uid.
12 13 14 |
# File 'lib/omnizip/formats/tar/entry.rb', line 12 def uid @uid end |
#uname ⇒ Object
Returns the value of attribute uname.
12 13 14 |
# File 'lib/omnizip/formats/tar/entry.rb', line 12 def uname @uname end |
Class Method Details
.calculate_checksum(header) ⇒ Integer
Calculate checksum for TAR header
81 82 83 84 85 86 87 88 |
# File 'lib/omnizip/formats/tar/entry.rb', line 81 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
48 49 50 |
# File 'lib/omnizip/formats/tar/entry.rb', line 48 def directory? @typeflag == TYPE_DIRECTORY end |
#file? ⇒ Boolean
Check if entry is a file
55 56 57 |
# File 'lib/omnizip/formats/tar/entry.rb', line 55 def file? @typeflag == TYPE_REGULAR || @typeflag.nil? || @typeflag.empty? end |
#full_name ⇒ String
Get full entry name (prefix + name)
69 70 71 72 73 74 75 |
# File 'lib/omnizip/formats/tar/entry.rb', line 69 def full_name if @prefix && !@prefix.empty? File.join(@prefix, @name) else @name end end |
#symlink? ⇒ Boolean
Check if entry is a symbolic link
62 63 64 |
# File 'lib/omnizip/formats/tar/entry.rb', line 62 def symlink? @typeflag == TYPE_SYMLINK end |