Class: ChunkyPNG::Chunk::Base
- Inherits:
-
Object
- Object
- ChunkyPNG::Chunk::Base
- Defined in:
- lib/chunky_png/chunk.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type, attributes = {}) ⇒ Base
constructor
A new instance of Base.
- #write(io) ⇒ Object
- #write_with_crc(io, content) ⇒ Object
Constructor Details
#initialize(type, attributes = {}) ⇒ Base
Returns a new instance of Base.
43 44 45 46 |
# File 'lib/chunky_png/chunk.rb', line 43 def initialize(type, attributes = {}) self.type = type attributes.each { |k, v| send("#{k}=", v) } end |
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
41 42 43 |
# File 'lib/chunky_png/chunk.rb', line 41 def type @type end |
Instance Method Details
#write(io) ⇒ Object
53 54 55 |
# File 'lib/chunky_png/chunk.rb', line 53 def write(io) write_with_crc(io, content || '') end |
#write_with_crc(io, content) ⇒ Object
48 49 50 51 |
# File 'lib/chunky_png/chunk.rb', line 48 def write_with_crc(io, content) io << [content.length].pack('N') << type << content io << [Zlib.crc32(content, Zlib.crc32(type))].pack('N') end |