pngsrc

package
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 7 Imported by: 0

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

View Source
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

View Source
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

func Extract(raw []byte) (string, error)

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

func InflateBounded(compressed []byte, max int64) (string, error)

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

type PNGTextChunk struct {
	Keyword string
	Text    string
}

PNGTextChunk is one decoded text chunk from a PNG image.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL