Class: VPK::VPKDirectoryEntry
- Inherits:
-
Object
- Object
- VPK::VPKDirectoryEntry
- Defined in:
- lib/vpk.rb
Instance Attribute Summary collapse
-
#archive_index ⇒ Object
Returns the value of attribute archive_index.
-
#crc ⇒ Object
Returns the value of attribute crc.
-
#entry_length ⇒ Object
Returns the value of attribute entry_length.
-
#entry_offset ⇒ Object
Returns the value of attribute entry_offset.
-
#extension ⇒ Object
Returns the value of attribute extension.
-
#file ⇒ Object
Returns the value of attribute file.
-
#path ⇒ Object
Returns the value of attribute path.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#preload_bytes ⇒ Object
Returns the value of attribute preload_bytes.
-
#terminator ⇒ Object
Returns the value of attribute terminator.
Class Method Summary collapse
Instance Method Summary collapse
- #full_path ⇒ Object
- #full_path=(path) ⇒ Object
- #mkdir_p ⇒ Object
- #read_payload(io, end_of_header = 0) ⇒ Object
- #valid? ⇒ Boolean
- #write_to_file(bath_path = nil) ⇒ Object
Instance Attribute Details
#archive_index ⇒ Object
Returns the value of attribute archive_index.
25 26 27 |
# File 'lib/vpk.rb', line 25 def archive_index @archive_index end |
#crc ⇒ Object
Returns the value of attribute crc.
23 24 25 |
# File 'lib/vpk.rb', line 23 def crc @crc end |
#entry_length ⇒ Object
Returns the value of attribute entry_length.
27 28 29 |
# File 'lib/vpk.rb', line 27 def entry_length @entry_length end |
#entry_offset ⇒ Object
Returns the value of attribute entry_offset.
26 27 28 |
# File 'lib/vpk.rb', line 26 def entry_offset @entry_offset end |
#extension ⇒ Object
Returns the value of attribute extension.
19 20 21 |
# File 'lib/vpk.rb', line 19 def extension @extension end |
#file ⇒ Object
Returns the value of attribute file.
21 22 23 |
# File 'lib/vpk.rb', line 21 def file @file end |
#path ⇒ Object
Returns the value of attribute path.
20 21 22 |
# File 'lib/vpk.rb', line 20 def path @path end |
#payload ⇒ Object
Returns the value of attribute payload.
30 31 32 |
# File 'lib/vpk.rb', line 30 def payload @payload end |
#preload_bytes ⇒ Object
Returns the value of attribute preload_bytes.
24 25 26 |
# File 'lib/vpk.rb', line 24 def preload_bytes @preload_bytes end |
#terminator ⇒ Object
Returns the value of attribute terminator.
28 29 30 |
# File 'lib/vpk.rb', line 28 def terminator @terminator end |
Class Method Details
.load_from(path) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/vpk.rb', line 32 def self.load_from(path) entry = VPKDirectoryEntry.new entry.payload = File.binread(path) entry.full_path = path entry end |
Instance Method Details
#full_path ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/vpk.rb', line 39 def full_path if path == " " "#{file}.#{extension}" else "#{path}/#{file}.#{extension}" end end |
#full_path=(path) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/vpk.rb', line 47 def full_path=(path) (path, file) = File.split(path) ext = File.extname(file) @path = path.gsub(/^\.\.?\//, "") @extension = ext.gsub(/^./, "") @file = File.basename(file, ext) end |
#mkdir_p ⇒ Object
65 66 67 |
# File 'lib/vpk.rb', line 65 def mkdir_p FileUtils.mkdir_p(@path) end |
#read_payload(io, end_of_header = 0) ⇒ Object
56 57 58 59 |
# File 'lib/vpk.rb', line 56 def read_payload(io, end_of_header = 0) io.seek(end_of_header + @entry_offset) @payload = io.read(@entry_length + @preload_bytes) end |
#valid? ⇒ Boolean
61 62 63 |
# File 'lib/vpk.rb', line 61 def valid? @crc == Zlib.crc32(@payload) end |
#write_to_file(bath_path = nil) ⇒ Object
69 70 71 72 73 |
# File 'lib/vpk.rb', line 69 def write_to_file(bath_path = nil) File.open(full_path, "wb") do |file| file.write @payload end end |