Help us shape the future of Go! Take the 2026 Go Developer Survey

extract

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeTextPlain   = "text/plain"
	TypeOctetStream = "application/octet-stream"
	TypeMarkdown    = "text/markdown"
	TypeJSON        = "application/json"
	TypeYAML        = "application/yaml"
	TypeCSV         = "text/csv"
	TypeXML         = "text/xml"
	TypeHTML        = "text/html"
	TypePDF         = "application/pdf"
	TypeDOCX        = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
	TypePPTX        = "application/vnd.openxmlformats-officedocument.presentationml.presentation"
	TypeXLSX        = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)

MIME types recognized by this package.

Variables

This section is empty.

Functions

func Detect

func Detect(name, contentType string, data []byte) string

Detect identifies the document type from magic bytes, falling back to contentType header and file name extension.

Types

type Result

type Result struct {
	Type      string // detected MIME type, e.g. "application/pdf", "text/html"
	Text      string // extracted plain text
	Extracted bool   // true when a type-specific extractor produced the text (false = pass-through)
}

Result holds the outcome of document detection and extraction.

func Extract

func Extract(name, contentType string, data []byte) (*Result, error)

Extract detects the document type and returns extracted plain text. Returns an error for empty data and for known-binary types that fail extraction. Unknown binary types return a descriptive error so the caller can skip the document.

Jump to

Keyboard shortcuts

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