File: base_chunk_reader.rb

package info (click to toggle)
ruby-wavefile 1.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,708 kB
  • sloc: ruby: 4,171; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 623 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module WaveFile
  module ChunkReaders
    # Internal
    class BaseChunkReader    # :nodoc:
      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

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