Class: CPIO::ArchiveEntry
- Inherits:
-
Object
- Object
- CPIO::ArchiveEntry
- Defined in:
- lib/excavate/extractors/cpio/cpio_old_format.rb
Constant Summary collapse
- TrailerMagic =
"TRAILER!!!"
- S_IFMT =
bitmask for the file type bitfields
0170000
- S_IFREG =
regular file
0100000
- S_IFDIR =
directory
0040000
- ExecutableMask =
Owner executable
(0100 | # Owner executable 0010 | # Group executable 0001)
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Other executable.
-
#filename ⇒ Object
readonly
Other executable.
Class Method Summary collapse
Instance Method Summary collapse
- #directory? ⇒ Boolean
- #executable? ⇒ Boolean
- #file? ⇒ Boolean
-
#initialize(header, filename, data) ⇒ ArchiveEntry
constructor
A new instance of ArchiveEntry.
- #mode ⇒ Object
- #to_data ⇒ Object
- #trailer? ⇒ Boolean
Constructor Details
#initialize(header, filename, data) ⇒ ArchiveEntry
Returns a new instance of ArchiveEntry.
152 153 154 155 156 |
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 152 def initialize(header, filename, data) @header = header @filename = filename @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Other executable
121 122 123 |
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 121 def data @data end |
#filename ⇒ Object (readonly)
Other executable
121 122 123 |
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 121 def filename @filename end |
Class Method Details
.from(io) ⇒ Object
127 128 129 130 131 132 |
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 127 def self.from(io) header = ArchiveHeader.from(io) filename = read_filename(header, io) data = read_data(header, io) new(header, filename, data) end |
.new_directory(opts) ⇒ Object
134 135 136 137 138 |
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 134 def self.new_directory(opts) mode = S_IFDIR | opts[:mode] header = ArchiveHeader.with_defaults(:mode => mode, :name => opts[:name], :filesize => 0) new(header, opts[:name], '') end |
.new_file(opts) ⇒ Object
140 141 142 143 144 145 |
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 140 def self.new_file(opts) mode = S_IFREG | opts[:mode] header = ArchiveHeader.with_defaults(:mode => mode, :name => opts[:name], :filesize => opts[:io].size) opts[:io].rewind new(header, opts[:name], opts[:io].read) end |
.new_trailer ⇒ Object
147 148 149 150 |
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 147 def self.new_trailer header = ArchiveHeader.with_defaults(:mode => S_IFREG, :name => TrailerMagic, :filesize => 0) new(header, TrailerMagic, '') end |
Instance Method Details
#directory? ⇒ Boolean
162 163 164 |
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 162 def directory? mode & S_IFMT == S_IFDIR end |
#executable? ⇒ Boolean
170 171 172 |
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 170 def executable? (mode & ExecutableMask) != 0 end |
#file? ⇒ Boolean
166 167 168 |
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 166 def file? mode & S_IFMT == S_IFREG end |
#mode ⇒ Object
174 175 176 |
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 174 def mode @mode ||= sprintf('%o', @header.mode).to_s.oct end |
#to_data ⇒ Object
178 179 180 |
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 178 def to_data sprintf("%s%s\000%s", @header.to_data, filename, data) end |
#trailer? ⇒ Boolean
158 159 160 |
# File 'lib/excavate/extractors/cpio/cpio_old_format.rb', line 158 def trailer? @filename == TrailerMagic && @data.size == 0 end |