Class: ChunkyPNG::Chunk::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/chunky_png/chunk.rb

Direct Known Subclasses

End, Generic, Header

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#typeObject

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