Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sio/csvio/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"strconv"
"unicode"

utext "golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"

"github.com/brimdata/super"
"github.com/brimdata/super/sup"
)
Expand Down Expand Up @@ -35,7 +38,8 @@ type ReaderOpts struct {
//}

func NewReader(sctx *super.Context, r io.Reader, opts ReaderOpts) *Reader {
preprocess := newPreprocess(r, opts.Delim)
utf8Reader := transform.NewReader(r, utext.UTF8BOM.NewDecoder())
preprocess := newPreprocess(utf8Reader, opts.Delim)
reader := csv.NewReader(preprocess)
if opts.Delim != 0 {
reader.Comma = opts.Delim
Expand Down
15 changes: 15 additions & 0 deletions sio/csvio/ztests/bom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# The input data leads with the UTF-8 representation of byte-order mark (BOM).
# See https://en.wikipedia.org/wiki/Byte_order_mark

script: |
head -c 3 with-bom.csv | xxd
super -s -i csv -c "cut a" with-bom.csv

inputs:
- name: with-bom.csv

outputs:
- name: stdout
data: |
00000000: efbb bf ...
{a:"foo"}
2 changes: 2 additions & 0 deletions sio/csvio/ztests/with-bom.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a,b
foo,bar
Loading