Class: ChunkyPNG::Chunk::Base

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

Direct Known Subclasses

CompressedText, End, Generic, Header, Text

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#typeObject

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