Module: RBStarbound::SBAsset6
- Defined in:
- lib/rbstarbound/sbasset6.rb
Class Attribute Summary collapse
-
.file_count ⇒ Object
readonly
Returns the value of attribute file_count.
-
.index ⇒ Object
readonly
Returns the value of attribute index.
-
.index_offset ⇒ Object
readonly
Returns the value of attribute index_offset.
-
.metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
.metadata_offset ⇒ Object
readonly
Returns the value of attribute metadata_offset.
-
.verbose ⇒ Object
Returns the value of attribute verbose.
Class Method Summary collapse
- .get(path) ⇒ Object
- .meta_header ⇒ Object
- .package(io) ⇒ Object
- .read_header ⇒ Object
- .read_index ⇒ Object
- .read_metadata ⇒ Object
- .rewind_to(pos) ⇒ Object
Class Attribute Details
.file_count ⇒ Object (readonly)
Returns the value of attribute file_count.
58 59 60 |
# File 'lib/rbstarbound/sbasset6.rb', line 58 def file_count @file_count end |
.index ⇒ Object (readonly)
Returns the value of attribute index.
58 59 60 |
# File 'lib/rbstarbound/sbasset6.rb', line 58 def index @index end |
.index_offset ⇒ Object (readonly)
Returns the value of attribute index_offset.
58 59 60 |
# File 'lib/rbstarbound/sbasset6.rb', line 58 def index_offset @index_offset end |
.metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
58 59 60 |
# File 'lib/rbstarbound/sbasset6.rb', line 58 def end |
.metadata_offset ⇒ Object (readonly)
Returns the value of attribute metadata_offset.
58 59 60 |
# File 'lib/rbstarbound/sbasset6.rb', line 58 def end |
.verbose ⇒ Object
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
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_header ⇒ Object
52 53 54 |
# File 'lib/rbstarbound/sbasset6.rb', line 52 def self. @package.read(5) end |
.package(io) ⇒ Object
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_header ⇒ Object
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_index ⇒ Object
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_metadata ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/rbstarbound/sbasset6.rb', line 40 def self. rewind_to() raise SBAsset6Error, 'Invalid index data' unless == '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 |