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.

chunked_join.go 1.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package ops
  2. import (
  3. "context"
  4. "io"
  5. "gitlink.org.cn/cloudream/common/pkgs/future"
  6. "gitlink.org.cn/cloudream/common/utils/io2"
  7. "gitlink.org.cn/cloudream/storage/common/pkgs/ioswitch"
  8. )
  9. type ChunkedJoin struct {
  10. InputIDs []ioswitch.StreamID `json:"inputIDs"`
  11. OutputID ioswitch.StreamID `json:"outputID"`
  12. ChunkSize int `json:"chunkSize"`
  13. }
  14. func (o *ChunkedJoin) Execute(sw *ioswitch.Switch, planID ioswitch.PlanID) error {
  15. strs, err := sw.WaitStreams(planID, o.InputIDs...)
  16. if err != nil {
  17. return err
  18. }
  19. var strReaders []io.Reader
  20. for _, s := range strs {
  21. strReaders = append(strReaders, s.Stream)
  22. }
  23. defer func() {
  24. for _, str := range strs {
  25. str.Stream.Close()
  26. }
  27. }()
  28. fut := future.NewSetVoid()
  29. sw.StreamReady(planID,
  30. ioswitch.NewStream(o.OutputID,
  31. io2.AfterReadClosedOnce(io2.ChunkedJoin(strReaders, o.ChunkSize), func(closer io.ReadCloser) {
  32. fut.SetVoid()
  33. }),
  34. ),
  35. )
  36. fut.Wait(context.TODO())
  37. return nil
  38. }
  39. func init() {
  40. OpUnion.AddT((*ChunkedJoin)(nil))
  41. }

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