class ChunkyPNG::Chunk::InternationalText

def self.read(type, content)

Raises:
  • (ChunkyPNG::NotSupported) - If the chunk refers to an unsupported compression method.
  • (ChunkyPNG::InvalidUTF8) - If the chunk contains data that is not UTF8-encoded text.

Returns:
  • (ChunkyPNG::Chunk::InternationalText) - The new End chunk instance.

Parameters:
  • content (String) -- The content read from the chunk.
  • type (String) -- The four character chunk type indicator (= "iTXt").
def self.read(type, content)
  keyword, compressed, compression, language_tag, translated_keyword, text = content.unpack("Z*CCZ*Z*a*")
  raise ChunkyPNG::NotSupported, "Compression flag #{compressed.inspect} not supported!" unless compressed == ChunkyPNG::UNCOMPRESSED_CONTENT || compressed == ChunkyPNG::COMPRESSED_CONTENT
  raise ChunkyPNG::NotSupported, "Compression method #{compression.inspect} not supported!" unless compression == ChunkyPNG::COMPRESSION_DEFAULT
  text = Zlib::Inflate.inflate(text) if compressed == ChunkyPNG::COMPRESSED_CONTENT
  text.force_encoding("utf-8")
  raise ChunkyPNG::InvalidUTF8, "Invalid unicode encountered in iTXt chunk" unless text.valid_encoding?
  translated_keyword.force_encoding("utf-8")
  raise ChunkyPNG::InvalidUTF8, "Invalid unicode encountered in iTXt chunk" unless translated_keyword.valid_encoding?
  new(keyword, text, language_tag, translated_keyword, compressed, compression)
end