Class: Omnizip::Formats::Xar::Entry
- Inherits:
-
Object
- Object
- Omnizip::Formats::Xar::Entry
- Includes:
- Constants
- 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.
-
#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
45 46 47 48 49 50 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 |
# File 'lib/omnizip/formats/xar/entry.rb', line 45 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.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def archived_checksum @archived_checksum end |
#archived_checksum_style ⇒ Object
Returns the value of attribute archived_checksum_style.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def archived_checksum_style @archived_checksum_style end |
#atime ⇒ Object
Returns the value of attribute atime.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def atime @atime end |
#ctime ⇒ Object
Returns the value of attribute ctime.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def ctime @ctime end |
#data ⇒ Object
Returns the value of attribute data.
22 23 24 |
# File 'lib/omnizip/formats/xar/entry.rb', line 22 def data @data end |
#data_encoding ⇒ Object
Returns the value of attribute data_encoding.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def data_encoding @data_encoding end |
#data_length ⇒ Object
Returns the value of attribute data_length.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def data_length @data_length end |
#data_offset ⇒ Object
Returns the value of attribute data_offset.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def data_offset @data_offset end |
#data_size ⇒ Object
Returns the value of attribute data_size.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def data_size @data_size end |
#device_major ⇒ Object
Returns the value of attribute device_major.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def device_major @device_major end |
#device_minor ⇒ Object
Returns the value of attribute device_minor.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def device_minor @device_minor end |
#ea ⇒ Object
Returns the value of attribute ea.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def ea @ea end |
#extracted_checksum ⇒ Object
Returns the value of attribute extracted_checksum.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def extracted_checksum @extracted_checksum end |
#extracted_checksum_style ⇒ Object
Returns the value of attribute extracted_checksum_style.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def extracted_checksum_style @extracted_checksum_style end |
#flags ⇒ Object
Returns the value of attribute flags.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def flags @flags end |
#gid ⇒ Object
Returns the value of attribute gid.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def gid @gid end |
#group ⇒ Object
Returns the value of attribute group.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def group @group end |
#id ⇒ Object
Returns the value of attribute id.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def id @id end |
#ino ⇒ Object
Returns the value of attribute ino.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def ino @ino end |
#link_target ⇒ Object
Returns the value of attribute link_target.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def link_target @link_target end |
#link_type ⇒ Object
Returns the value of attribute link_type.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def link_type @link_type end |
#mode ⇒ Object
Returns the value of attribute mode.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def mode @mode end |
#mtime ⇒ Object
Returns the value of attribute mtime.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def mtime @mtime end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def name @name end |
#nlink ⇒ Object
Returns the value of attribute nlink.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def nlink @nlink end |
#size ⇒ Object
Returns the value of attribute size.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def size @size end |
#type ⇒ Object
Returns the value of attribute type.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def type @type end |
#uid ⇒ Object
Returns the value of attribute uid.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def uid @uid end |
#user ⇒ Object
Returns the value of attribute user.
13 14 15 |
# File 'lib/omnizip/formats/xar/entry.rb', line 13 def user @user end |
Class Method Details
.type_from_mode(mode) ⇒ String
Get file type from mode
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/omnizip/formats/xar/entry.rb', line 149 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
128 129 130 |
# File 'lib/omnizip/formats/xar/entry.rb', line 128 def device? @type == TYPE_BLOCK || @type == TYPE_CHAR end |
#directory? ⇒ Boolean
Check if entry is a directory
100 101 102 |
# File 'lib/omnizip/formats/xar/entry.rb', line 100 def directory? @type == TYPE_DIRECTORY end |
#fifo? ⇒ Boolean
Check if entry is a FIFO
135 136 137 |
# File 'lib/omnizip/formats/xar/entry.rb', line 135 def fifo? @type == TYPE_FIFO end |
#file? ⇒ Boolean
Check if entry is a regular file
107 108 109 |
# File 'lib/omnizip/formats/xar/entry.rb', line 107 def file? @type == TYPE_FILE end |
#hardlink? ⇒ Boolean
Check if entry is a hard link
121 122 123 |
# File 'lib/omnizip/formats/xar/entry.rb', line 121 def hardlink? @type == TYPE_HARDLINK end |
#socket? ⇒ Boolean
Check if entry is a socket
142 143 144 |
# File 'lib/omnizip/formats/xar/entry.rb', line 142 def socket? @type == TYPE_SOCKET end |
#symlink? ⇒ Boolean
Check if entry is a symbolic link
114 115 116 |
# File 'lib/omnizip/formats/xar/entry.rb', line 114 def symlink? @type == TYPE_SYMLINK end |
#to_h ⇒ Hash
Convert entry to hash for TOC generation
165 166 167 168 169 170 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 |
# File 'lib/omnizip/formats/xar/entry.rb', line 165 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 |