Class: VPK::VPKDirectoryEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/vpk.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#archive_indexObject

Returns the value of attribute archive_index.



25
26
27
# File 'lib/vpk.rb', line 25

def archive_index
  @archive_index
end

#crcObject

Returns the value of attribute crc.



23
24
25
# File 'lib/vpk.rb', line 23

def crc
  @crc
end

#entry_lengthObject

Returns the value of attribute entry_length.



27
28
29
# File 'lib/vpk.rb', line 27

def entry_length
  @entry_length
end

#entry_offsetObject

Returns the value of attribute entry_offset.



26
27
28
# File 'lib/vpk.rb', line 26

def entry_offset
  @entry_offset
end

#extensionObject

Returns the value of attribute extension.



19
20
21
# File 'lib/vpk.rb', line 19

def extension
  @extension
end

#fileObject

Returns the value of attribute file.



21
22
23
# File 'lib/vpk.rb', line 21

def file
  @file
end

#pathObject

Returns the value of attribute path.



20
21
22
# File 'lib/vpk.rb', line 20

def path
  @path
end

#payloadObject

Returns the value of attribute payload.



30
31
32
# File 'lib/vpk.rb', line 30

def payload
  @payload
end

#preload_bytesObject

Returns the value of attribute preload_bytes.



24
25
26
# File 'lib/vpk.rb', line 24

def preload_bytes
  @preload_bytes
end

#terminatorObject

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_pathObject



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_pObject



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

Returns:

  • (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