Decode
Read SuperCSV files in Go — parse a .supr file and get typed values back.
Install
Go SDK
Add the SuperCSV module to your project, then import the supr package.
go get github.com/supercsv/supercsv
import "github.com/supercsv/supercsv/supr"
Quick
Decode a File
Load an entire .supr file into memory. Each row becomes a []any slice with values typed from the declared column schema.
file, err := supr.DecodeFile("data.supr")
if err != nil {
log.Fatal(err)
}
fmt.Println("Columns:", file.Header.Columns)
for _, row := range file.Rows {
fmt.Println(row) // []any with typed values
}
Streaming
Row-by-Row
For large files, decode in constant memory. The row slice is reused — copy it if you need to keep it.
f, _ := os.Open("data.supr")
defer f.Close()
d := supr.NewDecoder(f)
header := d.Header()
for d.Next() {
row := d.Row() // []any — reused on next call
id := row[0].(int64)
name := row[1].(string)
fmt.Printf("id=%d name=%s\n", id, name)
}
if err := d.Err(); err != nil {
log.Fatal(err)
}
Options
Decoder Options
Configure decoding behaviour — decode mode, field size limits, and strict-version enforcement.
d := supr.NewDecoder(f,
supr.WithDecodeMode(supr.DecodeFull), // default - full decode
supr.WithDecodeMaxFieldSize(1024*1024),
supr.WithDecodeStrictVersion("v1.0"), // require an explicit version directive matching v1.0
)
Working with Decoded Data
Enums
Decoded Enums
Enum fields decode to EnumField with .Index(), .Name(), and .Value() accessors.
ef := row[col].(supr.EnumField)
idx := ef.Index() // int32
name := ef.Name() // declared enum name
val := ef.Value() // declared enum value
Containers
Lists & Arrays
Lists and arrays decode to []any. 2D arrays decode to [][]any.
# 1D list / array
tags := row[col].([]any)
for _, tag := range tags {
fmt.Println(tag.(string))
}
# 2D array
matrix := row[col].([][]any)
for _, rowVals := range matrix {
for _, v := range rowVals {
fmt.Print(v.(int64), " ")
}
}