xberg

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package xberg provides a reusable, context-aware facade over the native Xberg Go binding.

Index

Constants

View Source
const (
	// DefaultMaxInputBytes limits untrusted reader and file inputs to 256 MiB.
	DefaultMaxInputBytes int64 = 256 << 20
	// DefaultSpillToDiskThreshold avoids the native binding's JSON byte-array
	// amplification for inputs larger than 8 MiB.
	DefaultSpillToDiskThreshold int64 = 8 << 20
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Native native.ExtractionConfig

	// MaxInputBytes is the maximum accepted file or reader size. Zero uses
	// DefaultMaxInputBytes. A negative value disables this facade-level limit;
	// Xberg's SecurityLimits still apply.
	MaxInputBytes int64

	// SpillToDiskThreshold controls when ExtractReader switches from memory to
	// a temporary file. Zero uses DefaultSpillToDiskThreshold. A negative value
	// keeps the whole reader in memory.
	SpillToDiskThreshold int64

	// TempDir optionally selects where spilled reader inputs are stored.
	TempDir string
}

Config contains process-wide extraction defaults. Native is intentionally exposed as an escape hatch so callers can use new Xberg capabilities without waiting for this package to add a wrapper for every field.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns RAG-friendly defaults while leaving OCR, chunking, image extraction, and model-backed features opt-in.

type Document

type Document = native.ExtractedDocument

type Extractor

type Extractor struct {
	// contains filtered or unexported fields
}

Extractor is safe for concurrent use. Configuration is cloned during New and per-call overrides are allocated for every extraction.

func New

func New(config *Config) (*Extractor, error)

func (*Extractor) Config

func (extractor *Extractor) Config() Config

Config returns a defensive copy of the effective configuration.

func (*Extractor) ExtractBytes

func (extractor *Extractor) ExtractBytes(ctx context.Context, data []byte, options ...Option) (*Result, error)

ExtractBytes extracts an in-memory document. Filename and MIME hints are strongly recommended for ZIP-container Office files.

func (*Extractor) ExtractFile

func (extractor *Extractor) ExtractFile(ctx context.Context, path string, options ...Option) (*Result, error)

ExtractFile extracts a local regular file without first loading it into Go memory.

func (*Extractor) ExtractReader

func (extractor *Extractor) ExtractReader(ctx context.Context, reader io.Reader, options ...Option) (*Result, error)

ExtractReader consumes reader. Small inputs stay in memory; larger inputs are transparently spooled to a temporary file to bound memory amplification.

type FileConfig

type FileConfig = native.FileExtractionConfig

type NativeConfig

type NativeConfig = native.ExtractionConfig

type Option

type Option func(*extractOptions) error

Option customizes one extraction without mutating the Extractor defaults.

func WithChunking

func WithChunking(config native.ChunkingConfig) Option

func WithFileConfig

func WithFileConfig(config native.FileExtractionConfig) Option

WithFileConfig replaces the per-file native Xberg overrides.

func WithFilename

func WithFilename(filename string) Option

func WithForceOCRPages

func WithForceOCRPages(pages ...uint32) Option

func WithMIMEType

func WithMIMEType(mimeType string) Option

func WithNativeFileConfig

func WithNativeFileConfig(apply func(*native.FileExtractionConfig)) Option

WithNativeFileConfig applies an advanced native Xberg override after the other options that precede it.

func WithOCR

func WithOCR(config native.OcrConfig) Option

func WithOutputFormat

func WithOutputFormat(format native.OutputFormat) Option

func WithPDF

func WithPDF(config native.PdfConfig) Option

func WithPages

func WithPages(config native.PageConfig) Option

func WithTimeout

func WithTimeout(timeout time.Duration) Option

type Result

type Result = native.ExtractionResult

Result and related aliases preserve access to all native Xberg information.

Jump to

Keyboard shortcuts

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