Skip to content

Commit

Permalink
fixup! fixup! Handle multi-document YAML streams
Browse files Browse the repository at this point in the history
  • Loading branch information
hairyhenderson committed Nov 15, 2019
1 parent 26f0e70 commit 40d5f34
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
23 changes: 10 additions & 13 deletions data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,19 @@ func YAMLArray(in string) ([]interface{}, error) {
}

// YAMLStream - parses a (potentially) multi-document YAML stream
func YAMLStream(in string) (ch chan interface{}, err error) {
ch = make(chan interface{})
func YAMLStream(in string) ([]interface{}, error) {
obj := []interface{}{}
s := strings.NewReader(in)
d := yaml.NewDecoder(s)
go func() {
for {
var o interface{}
err := d.Decode(&o)
if err == io.EOF {
close(ch)
break
}
ch <- o
for {
var o interface{}
err := d.Decode(&o)
if err == io.EOF {
break
}
}()
return ch, nil
obj = append(obj, o)
}
return obj, nil
}

// TOML - Unmarshal a TOML Object
Expand Down
2 changes: 1 addition & 1 deletion funcs/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (f *DataFuncs) YAMLArray(in interface{}) ([]interface{}, error) {
}

// YAMLStream -
func (f *DataFuncs) YAMLStream(in interface{}) (chan interface{}, error) {
func (f *DataFuncs) YAMLStream(in interface{}) ([]interface{}, error) {
return data.YAMLStream(conv.ToString(in))
}

Expand Down

0 comments on commit 40d5f34

Please sign in to comment.