Class: ChunkyPNG::Chunk::Base
- Inherits:
-
Object
- Object
- ChunkyPNG::Chunk::Base
- Defined in:
- lib/chunky_png/chunk.rb
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.
18 19 20 21 |
# File 'lib/chunky_png/chunk.rb', line 18 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.
16 17 18 |
# File 'lib/chunky_png/chunk.rb', line 16 def type @type end |
Instance Method Details
#write(io) ⇒ Object
28 29 30 |
# File 'lib/chunky_png/chunk.rb', line 28 def write(io) write_with_crc(io, content || '') end |
#write_with_crc(io, content) ⇒ Object
23 24 25 26 |
# File 'lib/chunky_png/chunk.rb', line 23 def write_with_crc(io, content) io << [content.length].pack('N') << type << content io << [Zlib.crc32(content, Zlib.crc32(type))].pack('N') end |