Sha256: ca543401eb2a13339102d7b1810a345a638b009c516cd09c82c45e3106ac0c18

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module LZO
  module LZOP
    class Header < BinData::Record
      MAGIC = "\x89\x4C\x5A\x4F\x00\x0D\x0A\x1A\x0A".force_encoding('BINARY')
      endian :big

      string :magic, read_length: 9, asserted_value: MAGIC

      struct :checksummable do
        uint16 :version
        uint16 :lib_version
        uint16 :version_needed, onlyif: -> { version >= 0x0940 }
        LzoMethod :lzo_method
        uint8 :level, onlyif: -> { version >= 0x940 }
        HeaderFlags :flags
        uint32 :filter, onlyif: -> { flags.include? :F_H_FILTER }
        uint32 :mode
        uint32 :mtime_low
        uint32 :mtime_high, onlyif: -> { version >= 0x0940 }
        uint8  :name_length, value: -> { name.length }
        string :name, read_length: :name_length
      end

      uint32 :checksum, asserted_value: -> { Raw.adler32(checksummable.to_binary_s) }
      struct :extra, onlyif: -> { checksummable.flags.include? :F_H_EXTRA_FIELD } do
        uint32 :extra_length
        string :extra_field, length: :extra_length
        uint32 :extra_checksum
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lzo-0.1.0 lib/lzo/lzop/header.rb