class ChunkyPNG::Chunk::Base
The base chunk class is the superclass for every chunk type. It contains methods to write the chunk to an output stream.
A subclass should implement the content
method, which gets called when the chunk gets written to a PNG datastream
@abstract
Attributes
The four-character type indicator for the chunk. This field is used to find the correct class for a chunk when it is loaded from a PNG stream. @return [String]
Public Class Methods
Source
# File lib/chunky_png/chunk.rb 69 def initialize(type, attributes = {}) 70 self.type = type 71 attributes.each { |k, v| send("#{k}=", v) } 72 end
Initializes the chunk instance. @param type [String] The four character chunk type indicator. @param attributes [Hash] A hash of attributes to set on this chunk.
Public Instance Methods
Source
# File lib/chunky_png/chunk.rb 88 def write(io) 89 write_with_crc(io, content || "") 90 end
Writes the chunk to the IO stream.
It will call the content
method to get the content for this chunk, and will calculate and append the checksum automatically. @param io [IO] The IO stream to write to.
Source
# File lib/chunky_png/chunk.rb 78 def write_with_crc(io, content) 79 io << [content.length].pack("N") << type << content 80 io << [Zlib.crc32(content, Zlib.crc32(type))].pack("N") 81 end
Writes the chunk to the IO stream, using the provided content. The checksum will be calculated and appended to the stream. @param io [IO] The IO stream to write to. @param content [String] The content for this chunk.