module ChunkyPNG::Chunk
def self.read(io)
-
(ChunkyPNG::Chung::Base)
- The loaded chunk instance.
Parameters:
-
io
(IO, #read
) -- The IO stream to read from.
def self.read(io) length, type = io.read(8).unpack('Na4') content = io.read(length) crc = io.read(4).unpack('N').first verify_crc!(type, content, crc) CHUNK_TYPES.fetch(type, Generic).read(type, content) end
def self.verify_crc!(type, content, found_crc)
-
(RuntimeError)
- An exception is raised if the found CRC value
Parameters:
-
content
(Fixnum
) -- The chunk's content. -
content
(String
) -- The chunk's content. -
type
(String
) -- The chunk's type.
def self.verify_crc!(type, content, found_crc) expected_crc = Zlib.crc32(content, Zlib.crc32(type)) raise "Chuck CRC mismatch!" if found_crc != expected_crc end