You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

local_uploading_iterator.go 1.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package iterator
  2. import (
  3. "io"
  4. "os"
  5. "path/filepath"
  6. "strings"
  7. )
  8. type UploadingObjectIterator = Iterator[*IterUploadingObject]
  9. type LocalUploadingIterator struct {
  10. pathRoot string
  11. filePathes []string
  12. currentIndex int
  13. }
  14. type IterUploadingObject struct {
  15. Path string
  16. Size int64
  17. File io.ReadCloser
  18. }
  19. func NewUploadingObjectIterator(pathRoot string, filePathes []string) *LocalUploadingIterator {
  20. return &LocalUploadingIterator{
  21. pathRoot: filepath.ToSlash(pathRoot),
  22. filePathes: filePathes,
  23. }
  24. }
  25. func (i *LocalUploadingIterator) MoveNext() (*IterUploadingObject, error) {
  26. if i.currentIndex >= len(i.filePathes) {
  27. return nil, ErrNoMoreItem
  28. }
  29. item, err := i.doMove()
  30. i.currentIndex++
  31. return item, err
  32. }
  33. func (i *LocalUploadingIterator) doMove() (*IterUploadingObject, error) {
  34. path := i.filePathes[i.currentIndex]
  35. info, err := os.Stat(path)
  36. if err != nil {
  37. return nil, err
  38. }
  39. file, err := os.Open(path)
  40. if err != nil {
  41. return nil, err
  42. }
  43. return &IterUploadingObject{
  44. Path: strings.TrimPrefix(filepath.ToSlash(path), i.pathRoot+"/"),
  45. Size: info.Size(),
  46. File: file,
  47. }, nil
  48. }
  49. func (i *LocalUploadingIterator) Close() {
  50. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。