miller/pkg/output/record_writer_nidx.go
2024-03-31 15:48:38 -04:00

41 lines
909 B
Go

package output
import (
"bufio"
"github.com/johnkerl/miller/pkg/cli"
"github.com/johnkerl/miller/pkg/mlrval"
"github.com/johnkerl/miller/pkg/types"
)
type RecordWriterNIDX struct {
writerOptions *cli.TWriterOptions
}
func NewRecordWriterNIDX(writerOptions *cli.TWriterOptions) (*RecordWriterNIDX, error) {
return &RecordWriterNIDX{
writerOptions: writerOptions,
}, nil
}
func (writer *RecordWriterNIDX) Write(
outrec *mlrval.Mlrmap,
_ *types.Context,
bufferedOutputStream *bufio.Writer,
outputIsStdout bool,
) error {
if outrec == nil {
// End of record stream: nothing special for this output format
return nil
}
for pe := outrec.Head; pe != nil; pe = pe.Next {
bufferedOutputStream.WriteString(pe.Value.String())
if pe.Next != nil {
bufferedOutputStream.WriteString(writer.writerOptions.OFS)
}
}
bufferedOutputStream.WriteString(writer.writerOptions.ORS)
return nil
}