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.

join.go 1.1 kB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package ops2
  2. import (
  3. "fmt"
  4. "io"
  5. "gitlink.org.cn/cloudream/common/pkgs/future"
  6. "gitlink.org.cn/cloudream/common/utils/io2"
  7. "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec"
  8. "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/utils"
  9. )
  10. func init() {
  11. exec.UseOp[*Join]()
  12. }
  13. type Join struct {
  14. Inputs []exec.VarID `json:"inputs"`
  15. Output exec.VarID `json:"output"`
  16. Length int64 `json:"length"`
  17. }
  18. func (o *Join) Execute(ctx *exec.ExecContext, e *exec.Executor) error {
  19. inputs, err := exec.BindArray[*exec.StreamValue](e, ctx.Context, o.Inputs)
  20. if err != nil {
  21. return err
  22. }
  23. var strReaders []io.Reader
  24. for _, s := range inputs {
  25. strReaders = append(strReaders, s.Stream)
  26. }
  27. defer func() {
  28. for _, str := range inputs {
  29. str.Stream.Close()
  30. }
  31. }()
  32. fut := future.NewSetVoid()
  33. e.PutVar(o.Output, &exec.StreamValue{
  34. Stream: io2.AfterReadClosedOnce(io2.Length(io2.Join(strReaders), o.Length), func(closer io.ReadCloser) {
  35. fut.SetVoid()
  36. }),
  37. })
  38. return fut.Wait(ctx.Context)
  39. }
  40. func (o *Join) String() string {
  41. return fmt.Sprintf("Join %v->%v", utils.FormatVarIDs(o.Inputs), o.Output)
  42. }

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