Documentation
¶
Overview ¶
Package pngsrc extracts PlantUML source from raw input bytes.
If the input begins with the PNG signature, Extract reads the embedded PlantUML source from a tEXt/zTXt/iTXt chunk whose keyword is "plantuml". Otherwise Extract returns the input as a UTF-8 string.
PNGTextChunks is exposed as a general-purpose iterator over a PNG image's text chunks; Extract is a thin wrapper around it.
Index ¶
Constants ¶
const MaxDecompressedSize = 16 << 20 // 16 MiB
MaxDecompressedSize bounds the size of a decompressed text chunk, guarding against deflate-bomb inputs. PlantUML diagrams in practice are far smaller.
Variables ¶
var ErrNoPlantUMLChunk = errors.New("pngsrc: no \"plantuml\" text chunk found in PNG")
ErrNoPlantUMLChunk is returned when raw is a PNG that does not contain a text chunk with the "plantuml" keyword.
Functions ¶
func Extract ¶
Extract returns the PlantUML source contained in raw.
When raw is not a PNG, the bytes are returned verbatim as a string. When raw is a PNG, the first tEXt/zTXt/iTXt chunk with keyword "plantuml" is decoded and returned. PNG inputs without such a chunk yield ErrNoPlantUMLChunk.
func InflateBounded ¶
InflateBounded decompresses zlib-encoded bytes with a hard cap on output length, returning an error if the output would exceed max bytes.
The cap defends against deflate-bomb inputs. Pass MaxDecompressedSize for PNG text-chunk decoding; other callers may pick a different limit.
func PNGTextChunks ¶
func PNGTextChunks(raw []byte) iter.Seq2[PNGTextChunk, error]
PNGTextChunks yields each tEXt/zTXt/iTXt chunk's decoded keyword and text in the order they appear. Iteration stops at the IEND chunk or end of input.
For non-PNG inputs the sequence is empty. Malformed PNG structure yields an error item and the iterator terminates; per-chunk decode errors do the same. Compressed text payloads are inflated up to MaxDecompressedSize bytes.
Types ¶
type PNGTextChunk ¶
PNGTextChunk is one decoded text chunk from a PNG image.