diff --git a/asv.go b/asv.go index 420ea20..79692aa 100644 --- a/asv.go +++ b/asv.go @@ -41,6 +41,32 @@ func NewDecoder (reader io.Reader) *Decoder { } } +// ReadCollection reads files until EOF and returns them in a collection. This +// function will return nil instead of io.EOF. +func (this *Decoder) ReadCollection () (collection Collection, err error) { + for { + file, _, err := this.ReadFile() + collection = append(collection, file) + if err == io.EOF { return collection, nil} + if err != nil { return collection, err } + } +} + +// ReadFile reads groups until a separator higher than or equal to FileSeparator +// is encountered, or an EOF is encountered. The function will then return the +// resulting File, as well as the separator that caused it to terminate. On EOF, +// it will return 0 for next and io.EOF for err. +func (this *Decoder) ReadFile () (file File, next rune, err error) { + for { + group, next, err := this.ReadGroup() + file = append(file, group) + if err != nil { return file, 0, err } + if next >= FileSeparator { + return file, next, nil + } + } +} + // ReadGroup reads records until a separator higher than or equal to // GroupSeparator is encountered, or an EOF is encountered. The function will // then return the resulting Group, as well as the separator that caused it to