Class: ID3Tag::Unsynchronization

Inherits:
Object
  • Object
show all
Defined in:
lib/id3tag/unsynchronization.rb

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Unsynchronization

Returns a new instance of Unsynchronization.



3
4
5
6
# File 'lib/id3tag/unsynchronization.rb', line 3

def initialize(input)
  @input = input
  @encoding = input.encoding
end

Instance Method Details

#applyObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/id3tag/unsynchronization.rb', line 8

def apply
  loop do
    current_byte = input_bytes.next
    output_bytes << current_byte
    next_byte = input_bytes.peek
    if (current_byte == 255) && (next_byte > 224)
      output_bytes << 0
    end
  end
end

#outputObject



31
32
33
# File 'lib/id3tag/unsynchronization.rb', line 31

def output
  output_bytes.pack("C*").force_encoding(@encoding)
end

#removeObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/id3tag/unsynchronization.rb', line 19

def remove
  prev_byte = nil
  loop do
    current_byte = input_bytes.next
    next_byte = input_bytes.peek rescue 0
    unless (prev_byte == 255) && (current_byte == 0) && (next_byte > 224)
      output_bytes << current_byte
    end
    prev_byte = current_byte
  end
end