Class: ChunkyPNG::Chunk::CompressedText

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

Overview

The CompressedText (zTXt) chunk contains keyword/value metadata about the PNG stream. In this chunk, the value is compressed using Deflate compression.

See Also:

Instance Attribute Summary (collapse)

Attributes inherited from Base

#type

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Base

#write, #write_with_crc

Constructor Details

- (CompressedText) initialize(keyword, value)



302
303
304
305
# File 'lib/chunky_png/chunk.rb', line 302

def initialize(keyword, value)
  super('zTXt')
  @keyword, @value = keyword, value
end

Instance Attribute Details

- (Object) keyword

Returns the value of attribute keyword



300
301
302
# File 'lib/chunky_png/chunk.rb', line 300

def keyword
  @keyword
end

- (Object) value

Returns the value of attribute value



300
301
302
# File 'lib/chunky_png/chunk.rb', line 300

def value
  @value
end

Class Method Details

+ (Object) read(type, content)



307
308
309
310
311
# File 'lib/chunky_png/chunk.rb', line 307

def self.read(type, content)
  keyword, compression, value = content.unpack('Z*Ca*')
  raise ChunkyPNG::NotSupported, "Compression method #{compression.inspect} not supported!" unless compression == ChunkyPNG::COMPRESSION_DEFAULT
  new(keyword, Zlib::Inflate.inflate(value))
end

Instance Method Details

- (Object) content

Creates the content to write to the stream, by concatenating the keyword with the deflated value, joined by a null character.



317
318
319
320
# File 'lib/chunky_png/chunk.rb', line 317

def content
  [keyword, ChunkyPNG::COMPRESSION_DEFAULT, Zlib::Deflate.deflate(value)].
    pack('Z*Ca*')
end