Module: RBStarbound::SBAsset6

Defined in:
lib/rbstarbound/sbasset6.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.file_countObject (readonly)

Returns the value of attribute file_count.



58
59
60
# File 'lib/rbstarbound/sbasset6.rb', line 58

def file_count
  @file_count
end

.indexObject (readonly)

Returns the value of attribute index.



58
59
60
# File 'lib/rbstarbound/sbasset6.rb', line 58

def index
  @index
end

.index_offsetObject (readonly)

Returns the value of attribute index_offset.



58
59
60
# File 'lib/rbstarbound/sbasset6.rb', line 58

def index_offset
  @index_offset
end

.metadataObject (readonly)

Returns the value of attribute metadata.



58
59
60
# File 'lib/rbstarbound/sbasset6.rb', line 58

def 
  
end

.metadata_offsetObject (readonly)

Returns the value of attribute metadata_offset.



58
59
60
# File 'lib/rbstarbound/sbasset6.rb', line 58

def 
  
end

.verboseObject

Returns the value of attribute verbose.



57
58
59
# File 'lib/rbstarbound/sbasset6.rb', line 57

def verbose
  @verbose
end

Class Method Details

.get(path) ⇒ Object

Raises:



14
15
16
17
18
19
# File 'lib/rbstarbound/sbasset6.rb', line 14

def self.get(path)
  raise SBAsset6Error, 'No package file given' if @package.nil?
  offset, length = @index[path]
  rewind_to(offset)
  @package.read(length)
end

.meta_headerObject



52
53
54
# File 'lib/rbstarbound/sbasset6.rb', line 52

def self.meta_header
  @package.read(5)
end

.package(io) ⇒ Object

Raises:



7
8
9
10
11
12
# File 'lib/rbstarbound/sbasset6.rb', line 7

def self.package(io)
  @package = io
  raise SBAsset6Error, 'No package file given' if @package.nil?
  read_header
  read_index
end

.read_headerObject

Raises:



21
22
23
24
25
26
# File 'lib/rbstarbound/sbasset6.rb', line 21

def self.read_header
  rewind_to(0)
  header,  = @package.read(16).unpack('A8Q>')
  raise SBAsset6Error, 'Invalid header' unless header == 'SBAsset6'
  
end

.read_indexObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rbstarbound/sbasset6.rb', line 28

def self.read_index
  puts 'Loading index...' if @verbose
  rewind_to(@index_offset)
  @index = {}
  @file_count.times do
    path = RBStarbound::SBON.read_string(@package)
    offset, length = @package.read(16).unpack('Q>Q>')
    @index[path] = [offset, length]
  end
  puts 'Index loaded.' if @verbose
end

.read_metadataObject

Raises:



40
41
42
43
44
45
46
# File 'lib/rbstarbound/sbasset6.rb', line 40

def self.
  rewind_to()
  raise SBAsset6Error, 'Invalid index data' unless meta_header == 'INDEX'
   = RBStarbound::SBON.read_map(@package)
  @file_count = RBStarbound::SBON.read_varint(@package)
  @index_offset = @package.pos
end

.rewind_to(pos) ⇒ Object



48
49
50
# File 'lib/rbstarbound/sbasset6.rb', line 48

def self.rewind_to(pos)
  @package.seek(pos, IO::SEEK_SET)
end