class ChunkyPNG::Chunk::Base
@abstract
the chunk gets written to a PNG datastream
A subclass should implement the content
method, which gets called when
methods to write the chunk to an output stream.
The base chunk class is the superclass for every chunk type. It contains
def initialize(type, attributes = {})
-
attributes
(Hash
) -- A hash of attributes to set on this chunk. -
type
(String
) -- The four character chunk type indicator.
def initialize(type, attributes = {}) self.type = type attributes.each { |k, v| send("#{k}=", v) } end
def write(io)
-
io
(IO
) -- The IO stream to write to.
def write(io) write_with_crc(io, content || "") end
def write_with_crc(io, content)
-
content
(String
) -- The content for this chunk. -
io
(IO
) -- The IO stream to write to.
def write_with_crc(io, content) io << [content.length].pack("N") << type << content io << [Zlib.crc32(content, Zlib.crc32(type))].pack("N") end