Class: Cabriolet::LIT::PieceBuilder
- Inherits:
-
Object
- Object
- Cabriolet::LIT::PieceBuilder
- Defined in:
- lib/cabriolet/lit/piece_builder.rb
Overview
Builds piece data for LIT files
Class Method Summary collapse
-
.build_piece0(file_data) ⇒ String
Build piece 0 data (file size information).
-
.build_piece1(directory) ⇒ String
Build piece 1 data (directory IFCM structure).
-
.build_piece2 ⇒ String
Build piece 2 data (index information).
Class Method Details
.build_piece0(file_data) ⇒ String
Build piece 0 data (file size information)
13 14 15 16 17 18 19 20 21 |
# File 'lib/cabriolet/lit/piece_builder.rb', line 13 def self.build_piece0(file_data) # Calculate total content size content_size = file_data.sum { |f| f[:uncompressed_size] } data = [Binary::LITStructures::Tags::SIZE_PIECE].pack("V") data += [content_size].pack("V") data += [0, 0].pack("VV") # High bits, reserved data end |
.build_piece1(directory) ⇒ String
Build piece 1 data (directory IFCM structure)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cabriolet/lit/piece_builder.rb', line 27 def self.build_piece1(directory) builder = DirectoryBuilder.new(chunk_size: directory[:chunk_size]) # Build IFCM header ifcm = Binary::LITStructures::IFCMHeader.new ifcm.tag = Binary::LITStructures::Tags::IFCM ifcm.version = 1 ifcm.chunk_size = directory[:chunk_size] ifcm.param = 0x100000 ifcm.reserved1 = 0xFFFFFFFF ifcm.reserved2 = 0xFFFFFFFF ifcm.num_chunks = directory[:num_chunks] ifcm.reserved3 = 0 data = ifcm.to_binary_s # Build AOLL chunk with directory entries directory[:entries].each do |entry| builder.add_entry( name: entry[:name], section: entry[:section], offset: entry[:offset], size: entry[:size], ) end aoll_chunk = builder.build_aoll_chunk data += aoll_chunk # Pad to fill piece (8KB standard) target_size = 8192 if data.bytesize < target_size data += "\x00" * (target_size - data.bytesize) end data end |
.build_piece2 ⇒ String
Build piece 2 data (index information)
68 69 70 71 |
# File 'lib/cabriolet/lit/piece_builder.rb', line 68 def self.build_piece2 # Minimal index data for foundation "\x00" * 512 end |