public function add_chunks($type, $key, $value) {
        if (strlen($key) > 79) {
            debugging('Key is too big');
        }

        // tEXt Textual data.
        // Keyword:        1-79 bytes (character string)
        // Null separator: 1 byte
        // Text:           n bytes (character string)
        $data = $key . "\0" . $value;
        $crc = pack("N", crc32($type . $data));
        $len = pack("N", strlen($data));

        // Chunk format: length + type + data + CRC.
        // CRC is a CRC-32 computed over the chunk type and chunk data.
        $newchunk = $len . $type . $data . $crc;

        $result = substr($this->_contents, 0, $this->_size - 12)
                . $newchunk
                . substr($this->_contents, $this->_size - 12, 12);

        return $result;
    }