Class: WaveFile::ChunkReaders::BaseChunkReader

Inherits:
Object
  • Object
show all
Defined in:
lib/wavefile/chunk_readers/base_chunk_reader.rb

Overview

Internal

Instance Method Summary collapse

Instance Method Details

#raise_error(exception_class, message) ⇒ Object

Raises:

  • (exception_class)


18
19
20
# File 'lib/wavefile/chunk_readers/base_chunk_reader.rb', line 18

def raise_error(exception_class, message)
  raise exception_class, "Not a supported wave file. #{message}"
end

#read_entire_chunk_body(chunk_id) ⇒ Object

:nodoc:



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/wavefile/chunk_readers/base_chunk_reader.rb', line 5

def read_entire_chunk_body(chunk_id)
  raw_bytes = @io.read(@chunk_size)
  if raw_bytes.nil?
    raw_bytes = ""
  end

  if raw_bytes.length < @chunk_size
    raise_error InvalidFormatError, "'#{chunk_id}' chunk indicated size of #{@chunk_size} bytes, but could only read #{raw_bytes.length} bytes."
  end

  raw_bytes
end