filetype

package
v0.0.0-...-c6ef63c Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertCSV

func ConvertCSV(data []byte, filename string) (string, error)

ConvertCSV converts CSV bytes to a markdown table.

func ConvertDOCX

func ConvertDOCX(data []byte, filename string) (string, error)

ConvertDOCX extracts text from DOCX bytes and returns markdown.

func ConvertImage

func ConvertImage(ctx context.Context, data []byte, filename string, rawURL string, contentType string, vision *VisionConfig) (string, error)

ConvertImage creates a markdown representation for an image file. If VisionConfig is provided and configured, it uses Cloudflare Workers AI to generate an AI description. Otherwise, it outputs metadata + image embed.

func ConvertJSON

func ConvertJSON(data []byte, filename string) (string, error)

ConvertJSON converts a JSON file to markdown with syntax highlighting.

func ConvertMD

func ConvertMD(data []byte) (string, error)

ConvertMD passes through markdown content as-is.

func ConvertODT

func ConvertODT(data []byte, filename string) (string, error)

ConvertODT converts OpenDocument Text (.odt) bytes to markdown.

func ConvertPDF

func ConvertPDF(data []byte, filename string) (string, error)

ConvertPDF extracts text from PDF bytes and returns markdown.

func ConvertTXT

func ConvertTXT(data []byte, filename string) (string, error)

ConvertTXT converts a plain text file to markdown.

func ConvertXLS

func ConvertXLS(data []byte, filename string) (string, error)

ConvertXLS converts legacy .xls (BIFF) bytes to markdown tables.

func ConvertXLSX

func ConvertXLSX(data []byte, filename string) (string, error)

ConvertXLSX converts XLSX bytes to markdown tables (one per sheet).

func ConvertXML

func ConvertXML(data []byte, filename string) (string, error)

ConvertXML converts an XML file to markdown with syntax highlighting.

func DescribeImage

func DescribeImage(ctx context.Context, cfg *VisionConfig, data []byte, contentType string) (string, error)

DescribeImage sends the image to Cloudflare Workers AI vision and returns a text description.

func FilenameFromURL

func FilenameFromURL(rawURL string) string

FilenameFromURL extracts a filename from a URL, decoding percent-encoding.

Types

type Type

type Type string

Type represents a supported file type.

const (
	TypeHTML Type = "html"
	TypePDF  Type = "pdf"
	TypeDOCX Type = "docx"
	TypeXLSX Type = "xlsx"
	TypeXLS  Type = "xls"
	TypeODT  Type = "odt"
	TypeCSV  Type = "csv"
	TypeJSON Type = "json"
	TypeXML  Type = "xml"
	TypeTXT  Type = "txt"
	TypeMD   Type = "md"
	TypePNG  Type = "png"
	TypeJPEG Type = "jpeg"
	TypeGIF  Type = "gif"
	TypeWEBP Type = "webp"
	TypeSVG  Type = "svg"
)

func Detect

func Detect(rawURL string, resp *http.Response, data []byte) Type

Detect determines file type using URL extension, final redirect URL, Content-Type, and magic bytes (in that order of priority).

func DetectFromBytes

func DetectFromBytes(data []byte) Type

DetectFromBytes uses magic byte signatures to identify file types. For ZIP-based formats (DOCX/XLSX), it peeks inside the archive markers.

func DetectFromContentType

func DetectFromContentType(ct string) Type

DetectFromContentType determines the file type from an HTTP Content-Type header.

func DetectFromURL

func DetectFromURL(rawURL string) Type

DetectFromURL guesses the file type from the URL path extension.

func (Type) IsImage

func (t Type) IsImage() bool

IsImage returns true if the type is an image format.

type VisionConfig

type VisionConfig struct {
	AccountID string
	APIToken  string
}

VisionConfig holds configuration for Cloudflare Workers AI vision.

func (*VisionConfig) IsConfigured

func (v *VisionConfig) IsConfigured() bool

IsConfigured returns true if the vision provider is configured.

Jump to

Keyboard shortcuts

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