dir.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. Copyright The containerd Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package fs
  14. import (
  15. "io"
  16. "os"
  17. )
  18. type dirReader struct {
  19. buf []os.DirEntry
  20. f *os.File
  21. err error
  22. }
  23. func (r *dirReader) Next() os.DirEntry {
  24. if len(r.buf) == 0 {
  25. infos, err := r.f.ReadDir(32)
  26. if err != nil {
  27. if err != io.EOF {
  28. r.err = err
  29. }
  30. return nil
  31. }
  32. r.buf = infos
  33. }
  34. if len(r.buf) == 0 {
  35. return nil
  36. }
  37. out := r.buf[0]
  38. r.buf[0] = nil
  39. r.buf = r.buf[1:]
  40. return out
  41. }
  42. func (r *dirReader) Err() error {
  43. return r.err
  44. }