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
- func BuildFileResult(content []byte, targetPath, operation string) *result.FileResult
- func BuildFileResultWithMIMEType(content []byte, targetPath, operation, mimeType string) *result.FileResult
- func EncodeArtifactCSV(content any, opts ParseCSVOptions) ([]byte, int, error)
- func EncodeCSVContent(content any, opts ParseCSVOptions) ([]byte, int, error)
- func EncodeFileContent(content any) ([]byte, error)
- func EncodeSpreadsheetContent(content any, opts SpreadsheetOptions) ([]byte, int, error)
- func EstimateWrittenRows(content any) int
- func IsSpreadsheetExtension(filePath string) bool
- func MIMETypeForPath(filePath, fallback string) string
- func ParseCSV(content []byte, opts ParseCSVOptions) (*result.FileResult, error)
- func ParseJSON(content []byte) (*result.FileResult, error)
- func ParseJSONWithLimits(content []byte, opts ParseJSONOptions) (*result.FileResult, error)
- func ParseSpreadsheet(content []byte, opts SpreadsheetOptions) (*result.FileResult, error)
- func QueryFormatStrings() []string
- type Field
- type File
- type ParseCSVOptions
- type ParseJSONOptions
- type QueryFormat
- type Schema
- type SchemaDiagnostic
- type SchemaIntrospector
- type SpreadsheetOptions
Constants ¶
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 ¶
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 ¶
EstimateWrittenRows returns the number of rows in content if it is a slice, or 0 otherwise.
func IsSpreadsheetExtension ¶
IsSpreadsheetExtension reports whether the path uses an Excelize-supported workbook extension.
func MIMETypeForPath ¶
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 ¶
Field represents one inferred field path and native type.
func InferCSVFields ¶
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 ¶
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 ¶
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 ¶
SchemaIntrospector retrieves file-backed data source schema metadata.