extractor

package
v0.0.0-...-0fdabcc Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package extractor is used to mine valuable information from a directory and its contents

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTextFile

func IsTextFile(ext string) bool

IsTextFile checks by extension

Types

type BinaryExtractor

type BinaryExtractor struct{}

BinaryExtractor extracts contents from a word document

func (BinaryExtractor) Extract

func (b BinaryExtractor) Extract(path string) (*ExtractedContent, error)

Extract tried to extract a binary content

type CodeExtractor

type CodeExtractor struct{}

CodeExtractor extracts contents from a code file

func (CodeExtractor) Extract

func (c CodeExtractor) Extract(path string) (*ExtractedContent, error)

Extract extracts content from a code file

type DocxExtractor

type DocxExtractor struct{}

DocxExtractor extracts contents from a word document

func (DocxExtractor) Extract

func (e DocxExtractor) Extract(path string) (*ExtractedContent, error)

Extract word document content

type ExcelExtractor

type ExcelExtractor struct{}

ExcelExtractor extracts excel file contents

func (ExcelExtractor) Extract

func (e ExcelExtractor) Extract(path string) (*ExtractedContent, error)

Extract extracts content from an excel file or CSV

type ExtractedContent

type ExtractedContent struct {
	Category string         // Type of content (e.g., "code", "document", "binary")
	Preview  string         // First few lines of content for quick viewing
	Lines    int            // Total line count (for text files)
	Details  map[string]any // Additional metadata specific to file type
}

ExtractedContent represents metadata extracted from a file. This is the common format returned by all extractor implementations.

type Extractor

type Extractor interface {
	// Extract reads a file and returns structured metadata about its contents.
	//
	// Parameters:
	//   - path: Full path to the file to extract
	//
	// Returns:
	//   - *ExtractedContent: Extracted metadata and preview
	//   - error: Any error encountered during extraction
	Extract(path string) (*ExtractedContent, error)
}

Extractor defines the interface for extracting content from files. Each file type (PDF, code, images, etc.) has its own implementation.

func DetectCategory

func DetectCategory(ext string) Extractor

DetectCategory determines the appropriate extractor for a file based on its extension.

This acts as a factory pattern, routing files to specialized extractors that understand their format.

Parameters:

  • ext: File extension including the dot (e.g., ".go", ".pdf")

Returns:

  • Extractor: Appropriate extractor implementation for the file type

File categories:

  • Code: .go, .dart, .js, .ts, .py, .java, .rb, .rs, .c, .cpp
  • PDF: .pdf
  • Word: .docx, .doc
  • Excel: .xlsx, .xls
  • Text: .md, .txt
  • Structured: .json, .yaml, .xml, .csv, etc.
  • Binary: Images, audio, video, or unknown formats

type GenericTextExtractor

type GenericTextExtractor struct{}

GenericTextExtractor is for files that could not be determined and are text like

func (GenericTextExtractor) Extract

func (e GenericTextExtractor) Extract(path string) (*ExtractedContent, error)

Extract tries to extract content from file at specified path

type MarkdownExtractor

type MarkdownExtractor struct{}

MarkdownExtractor extracts markdown files content

func (MarkdownExtractor) Extract

func (m MarkdownExtractor) Extract(path string) (*ExtractedContent, error)

Extract extracts content from a markdown file

type PDFExtractor

type PDFExtractor struct{}

PDFExtractor extracts content from a pdf file

func (PDFExtractor) Extract

func (e PDFExtractor) Extract(path string) (*ExtractedContent, error)

Extract extracts content from a pdf file

Jump to

Keyboard shortcuts

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