lister.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (C) 2019-2023 Nicola Murino
  2. //
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU Affero General Public License as published
  5. // by the Free Software Foundation, version 3.
  6. //
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU Affero General Public License for more details.
  11. //
  12. // You should have received a copy of the GNU Affero General Public License
  13. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. package sftpd
  15. import (
  16. "io"
  17. "os"
  18. )
  19. type listerAt []os.FileInfo
  20. // ListAt returns the number of entries copied and an io.EOF error if we made it to the end of the file list.
  21. // Take a look at the pkg/sftp godoc for more information about how this function should work.
  22. func (l listerAt) ListAt(f []os.FileInfo, offset int64) (int, error) {
  23. if offset >= int64(len(l)) {
  24. return 0, io.EOF
  25. }
  26. n := copy(f, l[offset:])
  27. if n < len(f) {
  28. return n, io.EOF
  29. }
  30. return n, nil
  31. }