Module: Gzsl
- Defined in:
- lib/gzsl.rb,
lib/gzsl/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
Class Method Details
.generate(output_file_path, image_file_paths) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/gzsl.rb', line 5 def self.generate( output_file_path, image_file_paths ) return false if image_file_paths.empty? File.open( output_file_path, "wb" ){|output_file| output_file.write Dastbytes::Binary.pack( :uint8, 0 ) output_file.write Dastbytes::Binary.pack( :uint16, image_file_paths.size ) image_file_paths.each{|image_file_path| File.open( image_file_path, "rb" ){|input_file| bytes = input_file.read output_file.write Dastbytes::Binary.pack( :uint32, bytes.size ) output_file.write bytes } } } true end |
.parse(path) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gzsl.rb', line 22 def self.parse( path ) return nil if ! File.exists?( path ) gzsl_hash = { :flags => 0, :images => [] } File.open( path, "rb" ){|f| gzsl_hash[ :flags ] = Dastbytes::Binary.unpack( :uint8, f.read( 1 ) ).first Dastbytes::Binary.unpack( :uint16, f.read( 2 ) ).first.times{ image_size = Dastbytes::Binary.unpack( :uint32, f.read( 4 ) ).first gzsl_hash[ :images ].push f.read( image_size ) } } gzsl_hash end |