Added utility method to DirEntries for reading all entries.

This commit is contained in:
Zach Klippenstein 2015-09-06 12:50:07 -07:00
parent 92af9f1b15
commit bdf8f854c3

View file

@ -24,6 +24,20 @@ type DirEntries struct {
err error err error
} }
// ReadAllDirEntries reads all the remaining directory entries into a slice,
// closes self, and returns any error.
// If err is non-nil, result will contain any entries read until the error occurred.
func (entries *DirEntries) ReadAll() (result []*DirEntry, err error) {
defer entries.Close()
for entries.Next() {
result = append(result, entries.Entry())
}
err = entries.Err()
return
}
func (entries *DirEntries) Next() bool { func (entries *DirEntries) Next() bool {
if entries.err != nil { if entries.err != nil {
return false return false