csv

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decoder added in v0.2.0

func Decoder(b []byte, v *[][]string) error

Decoder decodes CSV bytes into [][]string.

func Encoder added in v0.2.0

func Encoder(v [][]string) ([]byte, error)

Encoder encodes [][]string to CSV bytes.

func NewCodec

func NewCodec() encoding.Codec[[][]string, []byte]

NewCodec returns a CSV codec for [][]string. It is safe for concurrent use.

Example
package main

import (
	"fmt"

	"github.com/foomo/goencode/csv"
)

func main() {
	c := csv.NewCodec()

	records := [][]string{
		{"name", "age"},
		{"Alice", "30"},
	}

	encoded, err := c.Encode(records)
	if err != nil {
		fmt.Printf("Encode failed: %v\n", err)
		return
	}

	fmt.Printf("Encoded: %s", string(encoded))

	var decoded [][]string
	if err := c.Decode(encoded, &decoded); err != nil {
		fmt.Printf("Decode failed: %v\n", err)
		return
	}

	fmt.Printf("Decoded: %v\n", decoded)
}
Output:
Encoded: name,age
Alice,30
Decoded: [[name age] [Alice 30]]

func NewStreamCodec

func NewStreamCodec() encoding.StreamCodec[[][]string]

NewStreamCodec returns a CSV stream codec for [][]string. It is safe for concurrent use.

Example
package main

import (
	"bytes"
	"fmt"

	"github.com/foomo/goencode/csv"
)

func main() {
	c := csv.NewStreamCodec()

	records := [][]string{
		{"name", "age"},
		{"Alice", "30"},
	}

	var buf bytes.Buffer
	if err := c.Encode(&buf, records); err != nil {
		fmt.Printf("Encode failed: %v\n", err)
		return
	}

	var decoded [][]string
	if err := c.Decode(&buf, &decoded); err != nil {
		fmt.Printf("Decode failed: %v\n", err)
		return
	}

	fmt.Printf("Decoded: %v\n", decoded)
}
Output:
Decoded: [[name age] [Alice 30]]

func StreamDecoder added in v0.2.0

func StreamDecoder(r io.Reader, v *[][]string) error

StreamDecoder decodes [][]string from a CSV stream.

func StreamEncoder added in v0.2.0

func StreamEncoder(w io.Writer, v [][]string) error

StreamEncoder encodes [][]string to a CSV stream.

Types

This section is empty.

Jump to

Keyboard shortcuts

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