def METHOD_NAME(self):
    result = self.MAGIC
    for tag, chunkdata in sorted(list(self.chunks.items()), key=self.chunkorder):
        if len(tag) != 1:
            raise ValueError("Tag %r must be a length-1 string" % tag)
        result = result + tag
        if tag in self.SMALLCHUNKS:
            result += struct.pack(">H", len(chunkdata))
        else:
            result += struct.pack(">I", len(chunkdata))
        result += chunkdata
    return result