Class: AudioTag::ID3::V2::TagHeader

Inherits:
Header show all
Defined in:
lib/audio_tag/id3/v2/tag_header.rb

Constant Summary collapse

STRUCTURE =
%i[
  identifier identifier identifier
  version
  revision
  flags
  size size size size
].freeze
IDENTIFIER =
"ID3".freeze
INVALID_FLAG_MASK =
0x8F
EXPERIMENTAL_MASK =
0x10
EXTENDED_MASK =
0x20
UNSYNCHRONISED_MASK =
0x40

Instance Attribute Summary

Attributes inherited from Header

#bytes

Attributes inherited from StreamReader

#stream

Instance Method Summary collapse

Methods inherited from Header

#bytes_for

Methods inherited from StreamReader

#read, #read!, #read_byte, #read_byte!, #read_bytes, #read_bytes!, #read_bytes_until, #read_bytes_until!, #read_until, #read_until!

Constructor Details

#initialize(stream) ⇒ TagHeader

Returns a new instance of TagHeader.



20
21
22
23
24
25
# File 'lib/audio_tag/id3/v2/tag_header.rb', line 20

def initialize(stream)
  super

  validate_identifier!
  validate_flags!
end

Instance Method Details

#experimental?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/audio_tag/id3/v2/tag_header.rb', line 27

def experimental?
  (flags & EXPERIMENTAL_MASK).positive?
end

#extended?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/audio_tag/id3/v2/tag_header.rb', line 31

def extended?
  (flags & EXTENDED_MASK).positive?
end

#tag_sizeObject



39
40
41
# File 'lib/audio_tag/id3/v2/tag_header.rb', line 39

def tag_size
  @tag_size ||= Synchsafe.parse(*bytes_for(:size))
end

#total_sizeObject



43
44
45
# File 'lib/audio_tag/id3/v2/tag_header.rb', line 43

def total_size
  @total_size ||= tag_size + size
end

#unsynchronised?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/audio_tag/id3/v2/tag_header.rb', line 35

def unsynchronised?
  (flags & UNSYNCHRONISED_MASK).positive?
end