extract

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 14 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 downloaded attachments into plain text for an automated reader. Images are refused on purpose: there is no OCR, the reader is expected to look at them directly.

Index

Constants

This section is empty.

Variables

View Source
var DefaultLimits = Limits{MaxText: 200_000, MaxOutput: 64 << 20, MaxFileBytes: 50 << 20, MaxTotalBytes: 200 << 20, MaxEntries: 500, MaxDepth: 2}

DefaultLimits suit a chat attachment read by an agent.

View Source
var ErrImage = errors.New("image files have no text extraction (no OCR); download the file and view it")

ErrImage means the file is an image and has no text to extract.

Functions

This section is empty.

Types

type Limits

type Limits struct {
	MaxText       int   // bytes of text kept; the middle of longer text is cut
	MaxOutput     int64 // bytes of text produced before extraction stops
	MaxFileBytes  int64 // largest file, archive entry or document part read
	MaxTotalBytes int64 // total uncompressed bytes read, archives and parts included
	MaxEntries    int   // archive entries inspected
	MaxDepth      int   // nested archives followed
}

Limits bound the work done on untrusted input.

type Result

type Result struct {
	Text      string `json:"text"`
	Truncated bool   `json:"truncated"`
	Omitted   int64  `json:"omitted_bytes,omitempty"`
}

Result is extracted text; Omitted counts bytes cut from the middle.

func File

func File(ctx context.Context, filePath, name, mime string, lim Limits) (Result, error)

File extracts text from the file at filePath; name and mime come from the server and pick the format.

Jump to

Keyboard shortcuts

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