Class: Omnizip::Formats::Xar::Entry
- Inherits:
-
Object
- Object
- Omnizip::Formats::Xar::Entry
- Defined in:
- lib/omnizip/formats/xar/entry.rb
Overview
XAR file entry model
Represents a single file/directory/link in a XAR archive. Each entry has metadata and optional data.
Defined Under Namespace
Classes: ExtendedAttribute
Constant Summary
Constants included from Constants
Constants::CHECKSUM_ALGORITHMS, Constants::CHECKSUM_NAMES, Constants::CHECKSUM_SIZES, Constants::CKSUM_MD5, Constants::CKSUM_NONE, Constants::CKSUM_OTHER, Constants::CKSUM_SHA1, Constants::COMPRESSION_BZIP2, Constants::COMPRESSION_GZIP, Constants::COMPRESSION_LZMA, Constants::COMPRESSION_MIME_TYPES, Constants::COMPRESSION_NONE, Constants::COMPRESSION_XZ, Constants::DEFAULT_COMPRESSION, Constants::DEFAULT_COMPRESSION_LEVEL, Constants::DEFAULT_FILE_CHECKSUM, Constants::DEFAULT_TOC_CHECKSUM, Constants::HEADER_CKSUM_ALG_OFFSET, Constants::HEADER_MAGIC_OFFSET, Constants::HEADER_SIZE, Constants::HEADER_SIZE_EX, Constants::HEADER_SIZE_OFFSET, Constants::HEADER_TOC_COMPRESSED_OFFSET, Constants::HEADER_TOC_UNCOMPRESSED_OFFSET, Constants::HEADER_VERSION_OFFSET, Constants::MAGIC, Constants::MAGIC_BYTES, Constants::MAX_PATH_LENGTH, Constants::MIME_TYPE_TO_COMPRESSION, Constants::TOC_XML_DECLARATION, Constants::TYPE_BLOCK, Constants::TYPE_CHAR, Constants::TYPE_DIRECTORY, Constants::TYPE_FIFO, Constants::TYPE_FILE, Constants::TYPE_HARDLINK, Constants::TYPE_SOCKET, Constants::TYPE_SYMLINK, Constants::XAR_VERSION
Instance Attribute Summary collapse
-
#archived_checksum ⇒ Object
Returns the value of attribute archived_checksum.
-
#archived_checksum_style ⇒ Object
Returns the value of attribute archived_checksum_style.
-
#atime ⇒ Object
Returns the value of attribute atime.
-
#ctime ⇒ Object
Returns the value of attribute ctime.
-
#data ⇒ Object
Returns the value of attribute data.
-
#data_encoding ⇒ Object
Returns the value of attribute data_encoding.
-
#data_length ⇒ Object
Returns the value of attribute data_length.
-
#data_offset ⇒ Object
Returns the value of attribute data_offset.
-
#data_size ⇒ Object
Returns the value of attribute data_size.
-
#device_major ⇒ Object
Returns the value of attribute device_major.
-
#device_minor ⇒ Object
Returns the value of attribute device_minor.
-
#ea ⇒ Object
Returns the value of attribute ea.
-
#extracted_checksum ⇒ Object
Returns the value of attribute extracted_checksum.
-
#extracted_checksum_style ⇒ Object
Returns the value of attribute extracted_checksum_style.
-
#flags ⇒ Object
Returns the value of attribute flags.
-
#gid ⇒ Object
Returns the value of attribute gid.
-
#group ⇒ Object
Returns the value of attribute group.
-
#id ⇒ Object
Returns the value of attribute id.
-
#ino ⇒ Object
Returns the value of attribute ino.
-
#link_target ⇒ Object
Returns the value of attribute link_target.
-
#link_type ⇒ Object
Returns the value of attribute link_type.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#mtime ⇒ Object
Returns the value of attribute mtime.
-
#name ⇒ Object
Returns the value of attribute name.
-
#nlink ⇒ Object
Returns the value of attribute nlink.
-
#size ⇒ Object
Returns the value of attribute size.
-
#type ⇒ Object
Returns the value of attribute type.
-
#uid ⇒ Object
Returns the value of attribute uid.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
-
.type_from_mode(mode) ⇒ String
Get file type from mode.
Instance Method Summary collapse
-
#device? ⇒ Boolean
Check if entry is a device.
-
#directory? ⇒ Boolean
Check if entry is a directory.
- #entry_directory? ⇒ Boolean
- #entry_mtime ⇒ Object
- #entry_name ⇒ Object
- #entry_size ⇒ Object
-
#fifo? ⇒ Boolean
Check if entry is a FIFO.
-
#file? ⇒ Boolean
Check if entry is a regular file.
-
#hardlink? ⇒ Boolean
Check if entry is a hard link.
-
#initialize(name, options = {}) ⇒ Entry
constructor
Initialize entry.
-
#socket? ⇒ Boolean
Check if entry is a socket.
-
#symlink? ⇒ Boolean
Check if entry is a symbolic link.
-
#to_h ⇒ Hash
Convert entry to hash for TOC generation.
Constructor Details
#initialize(name, options = {}) ⇒ Entry
Initialize entry
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/omnizip/formats/xar/entry.rb', line 51 def initialize(name, = {}) @id = [:id] @name = name @type = [:type] || TYPE_FILE @mode = [:mode] || 0o644 @uid = [:uid] || 0 @gid = [:gid] || 0 @user = [:user] || "" @group = [:group] || "" @size = [:size] || 0 @ctime = [:ctime] @mtime = [:mtime] @atime = [:atime] # Data properties @data_offset = [:data_offset] || 0 @data_length = [:data_length] || 0 @data_size = [:data_size] || 0 @data_encoding = [:data_encoding] || COMPRESSION_NONE # Checksums @archived_checksum = [:archived_checksum] @archived_checksum_style = [:archived_checksum_style] @extracted_checksum = [:extracted_checksum] @extracted_checksum_style = [:extracted_checksum_style] # Links @link_type = [:link_type] @link_target = [:link_target] # Devices @device_major = [:device_major] @device_minor = [:device_minor] # Other metadata @ino = [:ino] @nlink = [:nlink] || 1 @flags = [:flags] @ea = [:ea] || [] # Extended attributes @data = nil end |
Instance Attribute Details
#archived_checksum ⇒ Object
Returns the value of attribute archived_checksum.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def archived_checksum @archived_checksum end |
#archived_checksum_style ⇒ Object
Returns the value of attribute archived_checksum_style.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def archived_checksum_style @archived_checksum_style end |
#atime ⇒ Object
Returns the value of attribute atime.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def atime @atime end |
#ctime ⇒ Object
Returns the value of attribute ctime.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def ctime @ctime end |
#data ⇒ Object
Returns the value of attribute data.
28 29 30 |
# File 'lib/omnizip/formats/xar/entry.rb', line 28 def data @data end |
#data_encoding ⇒ Object
Returns the value of attribute data_encoding.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def data_encoding @data_encoding end |
#data_length ⇒ Object
Returns the value of attribute data_length.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def data_length @data_length end |
#data_offset ⇒ Object
Returns the value of attribute data_offset.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def data_offset @data_offset end |
#data_size ⇒ Object
Returns the value of attribute data_size.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def data_size @data_size end |
#device_major ⇒ Object
Returns the value of attribute device_major.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def device_major @device_major end |
#device_minor ⇒ Object
Returns the value of attribute device_minor.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def device_minor @device_minor end |
#ea ⇒ Object
Returns the value of attribute ea.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def ea @ea end |
#extracted_checksum ⇒ Object
Returns the value of attribute extracted_checksum.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def extracted_checksum @extracted_checksum end |
#extracted_checksum_style ⇒ Object
Returns the value of attribute extracted_checksum_style.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def extracted_checksum_style @extracted_checksum_style end |
#flags ⇒ Object
Returns the value of attribute flags.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def flags @flags end |
#gid ⇒ Object
Returns the value of attribute gid.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def gid @gid end |
#group ⇒ Object
Returns the value of attribute group.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def group @group end |
#id ⇒ Object
Returns the value of attribute id.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def id @id end |
#ino ⇒ Object
Returns the value of attribute ino.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def ino @ino end |
#link_target ⇒ Object
Returns the value of attribute link_target.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def link_target @link_target end |
#link_type ⇒ Object
Returns the value of attribute link_type.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def link_type @link_type end |
#mode ⇒ Object
Returns the value of attribute mode.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def mode @mode end |
#mtime ⇒ Object
Returns the value of attribute mtime.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def mtime @mtime end |
#name ⇒ Object
Returns the value of attribute name.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def name @name end |
#nlink ⇒ Object
Returns the value of attribute nlink.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def nlink @nlink end |
#size ⇒ Object
Returns the value of attribute size.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def size @size end |
#type ⇒ Object
Returns the value of attribute type.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def type @type end |
#uid ⇒ Object
Returns the value of attribute uid.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def uid @uid end |
#user ⇒ Object
Returns the value of attribute user.
19 20 21 |
# File 'lib/omnizip/formats/xar/entry.rb', line 19 def user @user end |
Class Method Details
.type_from_mode(mode) ⇒ String
Get file type from mode
155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/omnizip/formats/xar/entry.rb', line 155 def self.type_from_mode(mode) case mode & 0o170000 when 0o040000 then TYPE_DIRECTORY when 0o100000 then TYPE_FILE when 0o120000 then TYPE_SYMLINK when 0o060000 then TYPE_BLOCK when 0o020000 then TYPE_CHAR when 0o010000 then TYPE_FIFO when 0o140000 then TYPE_SOCKET else TYPE_FILE end end |
Instance Method Details
#device? ⇒ Boolean
Check if entry is a device
134 135 136 |
# File 'lib/omnizip/formats/xar/entry.rb', line 134 def device? @type == TYPE_BLOCK || @type == TYPE_CHAR end |
#directory? ⇒ Boolean
Check if entry is a directory
106 107 108 |
# File 'lib/omnizip/formats/xar/entry.rb', line 106 def directory? @type == TYPE_DIRECTORY end |
#entry_directory? ⇒ Boolean
15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 15 def entry_directory? = type == :directory |
#entry_mtime ⇒ Object
17 |
# File 'lib/omnizip/formats/xar/entry.rb', line 17 def entry_mtime = mtime |
#entry_name ⇒ Object
14 |
# File 'lib/omnizip/formats/xar/entry.rb', line 14 def entry_name = name |
#entry_size ⇒ Object
16 |
# File 'lib/omnizip/formats/xar/entry.rb', line 16 def entry_size = size |
#fifo? ⇒ Boolean
Check if entry is a FIFO
141 142 143 |
# File 'lib/omnizip/formats/xar/entry.rb', line 141 def fifo? @type == TYPE_FIFO end |
#file? ⇒ Boolean
Check if entry is a regular file
113 114 115 |
# File 'lib/omnizip/formats/xar/entry.rb', line 113 def file? @type == TYPE_FILE end |
#hardlink? ⇒ Boolean
Check if entry is a hard link
127 128 129 |
# File 'lib/omnizip/formats/xar/entry.rb', line 127 def hardlink? @type == TYPE_HARDLINK end |
#socket? ⇒ Boolean
Check if entry is a socket
148 149 150 |
# File 'lib/omnizip/formats/xar/entry.rb', line 148 def socket? @type == TYPE_SOCKET end |
#symlink? ⇒ Boolean
Check if entry is a symbolic link
120 121 122 |
# File 'lib/omnizip/formats/xar/entry.rb', line 120 def symlink? @type == TYPE_SYMLINK end |
#to_h ⇒ Hash
Convert entry to hash for TOC generation
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/omnizip/formats/xar/entry.rb', line 171 def to_h hash = { id: @id, name: @name, type: @type, } hash[:mode] = format("0%03o", @mode) if @mode hash[:uid] = @uid if @uid hash[:gid] = @gid if @gid hash[:user] = @user unless @user.to_s.empty? hash[:group] = @group unless @group.to_s.empty? hash[:size] = @size if @size&.positive? # Timestamps hash[:ctime] = (@ctime) if @ctime hash[:mtime] = (@mtime) if @mtime hash[:atime] = (@atime) if @atime # Data section if @data_size&.positive? || file? data_hash = {} data_hash[:offset] = @data_offset data_hash[:size] = @data_length if @data_length&.positive? data_hash[:length] = @data_size if @data_size&.positive? if @data_encoding && @data_encoding != COMPRESSION_NONE data_hash[:encoding] = COMPRESSION_MIME_TYPES[@data_encoding] || @data_encoding end if @archived_checksum data_hash[:archived_checksum] = @archived_checksum end if @archived_checksum_style data_hash[:archived_checksum_style] = @archived_checksum_style end if @extracted_checksum data_hash[:extracted_checksum] = @extracted_checksum end if @extracted_checksum_style data_hash[:extracted_checksum_style] = @extracted_checksum_style end hash[:data] = data_hash end # Links if @link_target hash[:link] = { type: @link_type, target: @link_target } end # Devices if device? device_hash = {} device_hash[:major] = @device_major if @device_major device_hash[:minor] = @device_minor if @device_minor hash[:device] = device_hash end # Extended attributes if @ea&.any? hash[:ea] = @ea.map do |attr| ea_hash = { name: attr.name } ea_hash[:offset] = attr.data_offset ea_hash[:size] = attr.data_length ea_hash[:length] = attr.data_size ea_hash end end hash end |