extract

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package extract turns Office Open XML (Word, Excel, PowerPoint) and OpenDocument files into plain text, in process, with the standard library only. Documents are untrusted: every read is bounded (entries, bytes per part, bytes per document, bytes in one tag, nesting depth, text produced, row size), and no declaration or entity is processed.

Index

Constants

View Source
const (
	MaxParts      = 10000     // zip entries
	MaxPartBytes  = 64 << 20  // decompressed bytes of one part
	MaxTotalBytes = 256 << 20 // decompressed bytes of all parts read
	MaxText       = 16 << 20  // bytes of text produced; beyond it the result is Truncated

	MaxTag       = 1 << 20 // bytes in one tag, its attributes included
	MaxDepth     = 4096    // elements open at once
	MaxDirectory = 4 << 20 // bytes of the archive's central directory
)

Limits. A document needing more is refused, never partly decompressed into memory.

Variables

View Source
var (
	// ErrUnsupported means the file is not a document of its kind: not a zip, or a required part
	// is missing or not well-formed XML.
	ErrUnsupported = errors.New("not a readable document")
	// ErrTooLarge means a limit stopped the read before any text could be trusted complete.
	ErrTooLarge = errors.New("document too large to extract")
)

Functions

func Kind

func Kind(ext string) string

Kind names the document type of extension ext (no dot, any case), or "" when Text cannot read it.

Types

type Result

type Result struct {
	Text      string
	Truncated bool
}

Result is a document's text. Truncated is set when it was cut at MaxText.

func Text

func Text(ctx context.Context, r io.ReaderAt, size int64, ext string) (Result, error)

Text extracts the text of the document of extension ext held in r (size bytes).

Jump to

Keyboard shortcuts

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