Class: Cabriolet::Models::KWAJHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/cabriolet/models/kwaj_header.rb

Overview

Represents a KWAJ file header

KWAJ files support multiple compression methods and optional headers determined by flag bits. The header structure is more flexible than SZDD.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeKWAJHeader

Initialize a new KWAJ header



39
40
41
42
43
44
45
46
47
# File 'lib/cabriolet/models/kwaj_header.rb', line 39

def initialize
  @comp_type = Constants::KWAJ_COMP_NONE
  @data_offset = 0
  @headers = 0
  @length = nil
  @filename = nil
  @extra = nil
  @extra_length = 0
end

Instance Attribute Details

#comp_typeInteger

Compression type

Returns:

  • (Integer)

    One of KWAJ_COMP_* constants



12
13
14
# File 'lib/cabriolet/models/kwaj_header.rb', line 12

def comp_type
  @comp_type
end

#data_offsetInteger

Offset to compressed data

Returns:

  • (Integer)

    Byte offset where compressed data starts



16
17
18
# File 'lib/cabriolet/models/kwaj_header.rb', line 16

def data_offset
  @data_offset
end

#extraString?

Extra text data

Returns:

  • (String, nil)

    Extra text data if present



32
33
34
# File 'lib/cabriolet/models/kwaj_header.rb', line 32

def extra
  @extra
end

#extra_lengthInteger

Length of extra data

Returns:

  • (Integer)

    Number of bytes in extra data



36
37
38
# File 'lib/cabriolet/models/kwaj_header.rb', line 36

def extra_length
  @extra_length
end

#filenameString?

Original filename

Returns:

  • (String, nil)

    Original filename if present



28
29
30
# File 'lib/cabriolet/models/kwaj_header.rb', line 28

def filename
  @filename
end

#headersInteger

Header flags

Returns:

  • (Integer)

    Bitfield indicating which optional headers are present



20
21
22
# File 'lib/cabriolet/models/kwaj_header.rb', line 20

def headers
  @headers
end

#lengthInteger?

Uncompressed length

Returns:

  • (Integer, nil)

    Length of uncompressed data if present



24
25
26
# File 'lib/cabriolet/models/kwaj_header.rb', line 24

def length
  @length
end

Instance Method Details

#compression_nameString

Get human-readable compression type name

Returns:

  • (String)

    Compression type name



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cabriolet/models/kwaj_header.rb', line 52

def compression_name
  case @comp_type
  when Constants::KWAJ_COMP_NONE
    "None"
  when Constants::KWAJ_COMP_XOR
    "XOR"
  when Constants::KWAJ_COMP_SZDD
    "SZDD"
  when Constants::KWAJ_COMP_LZH
    "LZH"
  when Constants::KWAJ_COMP_MSZIP
    "MSZIP"
  else
    "Unknown (#{@comp_type})"
  end
end

#has_extra_text?Boolean

Check if header has extra text

Returns:

  • (Boolean)

    true if extra text is present



93
94
95
# File 'lib/cabriolet/models/kwaj_header.rb', line 93

def has_extra_text?
  @headers.anybits?(Constants::KWAJ_HDR_HASEXTRATEXT)
end

#has_file_extension?Boolean

Check if header has file extension

Returns:

  • (Boolean)

    true if file extension is present



86
87
88
# File 'lib/cabriolet/models/kwaj_header.rb', line 86

def has_file_extension?
  @headers.anybits?(Constants::KWAJ_HDR_HASFILEEXT)
end

#has_filename?Boolean

Check if header has filename

Returns:

  • (Boolean)

    true if filename is present



79
80
81
# File 'lib/cabriolet/models/kwaj_header.rb', line 79

def has_filename?
  @headers.anybits?(Constants::KWAJ_HDR_HASFILENAME)
end

#has_length?Boolean

Check if header has length field

Returns:

  • (Boolean)

    true if length is present



72
73
74
# File 'lib/cabriolet/models/kwaj_header.rb', line 72

def has_length?
  @headers.anybits?(Constants::KWAJ_HDR_HASLENGTH)
end