-
Notifications
You must be signed in to change notification settings - Fork 0
/
format.go
24 lines (21 loc) · 1.06 KB
/
format.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Package format package contains interfaces to implement to allow read/write of various file types.
package format
import "os"
// Readable is an interface for file types that can be read from.
type Readable interface {
// Initialize should initialize a encoding/<format> reader from the underlying file.
Initialize(file *os.File) error
// ReadHeader should return a list of column names.
ReadHeader() ([]string, error)
// ReadRecord should read a single record and return it as a map[string]string where column name is key and column value is value.
ReadRecord(headers []string) (map[string]string, error)
}
// Writable is for file types that can be written to.
type Writable interface {
// WriteHeader should be called at the beginning of the file write process.
WriteHeader(file *os.File, columns []string) error
// WriteRecord should be called for every record in the source data.
WriteRecord(file *os.File, row map[string]string, index int) error
// WriteFooter should be called after every record has been written with WriteRecord.
WriteFooter(file *os.File) error
}