filedata

package
v0.5.0-linux-arm64 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 20 Imported by: ? 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 filedata provides shared file-format detection, CSV/JSON/spreadsheet parsing, and schema inference helpers used by file-backed data source connectors (FTP, Git).

Index

Constants

View Source
const DefaultSpreadsheetSheetName = "Sheet1"

Variables

This section is empty.

Functions

func BuildFileResult

func BuildFileResult(content []byte, targetPath, operation string) *result.FileResult

BuildFileResult returns a file execution result with safe metadata and copied bytes.

func BuildFileResultWithMIMEType

func BuildFileResultWithMIMEType(
	content []byte,
	targetPath,
	operation,
	mimeType string,
) *result.FileResult

BuildFileResultWithMIMEType returns a file result using a provider media type fallback.

func EncodeArtifactCSV

func EncodeArtifactCSV(content any, opts ParseCSVOptions) ([]byte, int, error)

EncodeArtifactCSV preserves records that the standard reader would discard as blank lines.

func EncodeCSVContent

func EncodeCSVContent(content any, opts ParseCSVOptions) ([]byte, int, error)

EncodeCSVContent serializes content as CSV bytes using the provided options. content must be a []any of map[string]any objects. Raw CSV strings are handled by the caller before invoking this function. Returns the encoded bytes, the number of written rows, and any error.

func EncodeFileContent

func EncodeFileContent(content any) ([]byte, error)

EncodeFileContent converts native file sink content into bytes for raw writes.

func EncodeSpreadsheetContent

func EncodeSpreadsheetContent(content any, opts SpreadsheetOptions) ([]byte, int, error)

EncodeSpreadsheetContent serializes row-object content into a workbook.

func EstimateWrittenRows

func EstimateWrittenRows(content any) int

EstimateWrittenRows returns the number of rows in content if it is a slice, or 0 otherwise.

func IsSpreadsheetExtension

func IsSpreadsheetExtension(filePath string) bool

IsSpreadsheetExtension reports whether the path uses an Excelize-supported workbook extension.

func MIMETypeForPath

func MIMETypeForPath(filePath, fallback string) string

MIMETypeForPath returns a safe file payload media type based on extension or fallback.

func ParseCSV

func ParseCSV(content []byte, opts ParseCSVOptions) (*result.FileResult, error)

ParseCSV parses CSV content using the provided options and returns a FileResult.

func ParseJSON

func ParseJSON(content []byte) (*result.FileResult, error)

ParseJSON parses JSON content and returns a FileResult with rows and sorted column names.

func ParseJSONWithLimits

func ParseJSONWithLimits(content []byte, opts ParseJSONOptions) (*result.FileResult, error)

ParseJSONWithLimits parses JSON content with row and byte safety limits.

func ParseSpreadsheet

func ParseSpreadsheet(content []byte, opts SpreadsheetOptions) (*result.FileResult, error)

ParseSpreadsheet parses workbook content into row objects.

func QueryFormatStrings

func QueryFormatStrings() []string

QueryFormatStrings returns a slice of all String values of the enum

Types

type Field

type Field struct {
	Name string
	Type string
}

Field represents one inferred field path and native type.

func InferCSVFields

func InferCSVFields(content []byte) ([]Field, error)

InferCSVFields infers field names from CSV content column headers. All inferred CSV fields have type string; headless CSVs get an additional csv_row array field.

func InferJSONFields

func InferJSONFields(content []byte) ([]Field, error)

InferJSONFields infers field paths and types from JSON content. Nested paths use dot notation; array fields carry a [] suffix.

func InferSpreadsheetFields

func InferSpreadsheetFields(content []byte, opts SpreadsheetOptions) ([]Field, error)

InferSpreadsheetFields infers string fields from the selected worksheet.

type File

type File struct {
	ResourceID string `json:"resource_id,omitempty"`
	MIMEType   string `json:"mime_type,omitempty"`
	SizeBytes  *int64 `json:"size_bytes,omitempty"`
	Name       string
	Fields     []Field
}

File represents one discoverable file and its inferred fields.

type ParseCSVOptions

type ParseCSVOptions struct {
	Delimiter string
	HasHeader *bool
	MaxRows   int
	MaxBytes  int64
	// MaxResultBytes bounds row materialization using a lower bound on JSON size.
	MaxResultBytes int64
}

ParseCSVOptions controls how CSV content is parsed.

type ParseJSONOptions

type ParseJSONOptions struct {
	MaxRows  int
	MaxBytes int64
}

ParseJSONOptions controls how JSON content is parsed.

type QueryFormat

type QueryFormat int

QueryFormat determines how file content should be parsed.

const (
	QueryFormatUnknown     QueryFormat = iota // unknown
	QueryFormatAuto                           // auto
	QueryFormatCSV                            // csv
	QueryFormatJSON                           // json
	QueryFormatFile                           // file
	QueryFormatSpreadsheet                    // spreadsheet
)

func DetectFormat

func DetectFormat(format QueryFormat, filePath string) (QueryFormat, error)

DetectFormat resolves a read format and requires a matching extension for structured data.

func DetectWriteFormat

func DetectWriteFormat(format QueryFormat, filePath string) (QueryFormat, error)

DetectWriteFormat determines the write format from an explicit setting or file extension, defaulting to JSON for unknown extensions.

func ParseQueryFormat

func ParseQueryFormat(value string) QueryFormat

ParseQueryFormat maps external format text to a supported query format.

func QueryFormatString

func QueryFormatString(s string) (QueryFormat, error)

QueryFormatString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func QueryFormatValues

func QueryFormatValues() []QueryFormat

QueryFormatValues returns all values of the enum

func (QueryFormat) IsAQueryFormat

func (i QueryFormat) IsAQueryFormat() bool

IsAQueryFormat returns "true" if the value is listed in the enum definition. "false" otherwise

func (QueryFormat) MarshalJSON

func (i QueryFormat) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for QueryFormat

func (QueryFormat) MarshalText

func (i QueryFormat) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for QueryFormat

func (QueryFormat) String

func (i QueryFormat) String() string

func (*QueryFormat) UnmarshalJSON

func (i *QueryFormat) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for QueryFormat

func (*QueryFormat) UnmarshalText

func (i *QueryFormat) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for QueryFormat

type Schema

type Schema struct {
	Files       []File
	Diagnostics []SchemaDiagnostic
}

Schema represents discovered file schemas for a file-backed data source.

type SchemaDiagnostic

type SchemaDiagnostic struct {
	Name     string
	Target   string
	Severity string
	Code     string
	Message  string
}

SchemaDiagnostic reports a non-fatal file schema sampling issue.

type SchemaIntrospector

type SchemaIntrospector interface {
	IntrospectSchema(ctx context.Context) (*Schema, error)
}

SchemaIntrospector retrieves file-backed data source schema metadata.

type SpreadsheetOptions

type SpreadsheetOptions struct {
	Sheet     string
	Range     string
	HasHeader *bool
	MaxRows   int
	// MaxBytes bounds input, decompression and parsing work during import.
	MaxBytes int64
	FilePath string
}

SpreadsheetOptions controls spreadsheet import/export behavior.

Jump to

Keyboard shortcuts

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