csv

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package csv wraps encoding/csv as a codec.Codec implementation. The CSV format serialises a matrix of strings; the codec accepts [][]string for Marshal and writes into *[][]string on Unmarshal.

Package csv — range 0.3.8.* (ADR 0005 service/codec/csv block).

Package csv — declares the sentinel *errs.Error values for CSV.

Index

Constants

View Source
const CodeCSVMarshalFailed errs.Code = 0x00_03_08_01 // 0.3.8.1

CodeCSVMarshalFailed identifies a failure inside encoding/csv.Writer.

View Source
const CodeCSVUnmarshalFailed errs.Code = 0x00_03_08_02 // 0.3.8.2

CodeCSVUnmarshalFailed identifies a failure inside encoding/csv.Reader.

View Source
const CodeCSVValueInvalid errs.Code = 0x00_03_08_03 // 0.3.8.3

CodeCSVValueInvalid identifies a Marshal / Unmarshal call whose target is not a *[][]string (CSV only serialises a records matrix).

Variables

View Source
var (
	// MarshalFailed wraps a failure from encoding/csv.Writer.Write(All).
	MarshalFailed = errs.Define(CodeCSVMarshalFailed, "MARSHAL_FAILED",
		"CSV encoding failed",
		"service/codec/csv: encoding/csv.Writer.WriteAll returned an error")

	// UnmarshalFailed wraps a failure from encoding/csv.Reader.ReadAll.
	UnmarshalFailed = errs.Define(CodeCSVUnmarshalFailed, "UNMARSHAL_FAILED",
		"CSV decoding failed",
		"service/codec/csv: encoding/csv.Reader.ReadAll returned an error")

	// ValueInvalid fires when the caller does not pass a *[][]string.
	ValueInvalid = errs.Define(CodeCSVValueInvalid, "VALUE_INVALID",
		"CSV codec requires a [][]string value",
		"service/codec/csv: Marshal/Unmarshal called with non-[][]string argument")
)
View Source
var (
	//: Codec is the CSV singleton, registered with core/codec at package
	//: load. Binding the registration result to a named var is more
	//: idiomatic than `var _ = codec.Register(...)` and keeps us clear of
	//: init(). The singleton has escapeFormulas=false for wire-format
	//: fidelity — consumers whose output is read by a spreadsheet
	//: application should use NewWithEscape(true) instead.
	Codec codec.Codec = codec.Register(&csvCodec{})
)

Package-level vars: the Marshal-buffer pool plus the singleton registered with core/codec at package load.

Functions

func New

func New() codec.Codec

New returns the CSV singleton with escapeFormulas disabled. This preserves the v1 API and keeps the wire-format lossless for pipe-to-pipe use.

func NewWithEscape

func NewWithEscape(escape bool) codec.Codec

NewWithEscape returns a fresh CSV codec with the formula-injection mitigation toggled on or off. Use this constructor when the encoded output will be opened in a spreadsheet app (Excel, LibreOffice, Google Sheets): without the mitigation an attacker-influenced cell starting with "=" evaluates as a formula at open time, which is OWASP CSV Injection (CWE-1236). The returned codec is not registered with the core/codec singleton registry.

Types

This section is empty.

Jump to

Keyboard shortcuts

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