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 951 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 Join struct {
  10. Inputs []*ioswitch.StreamVar `json:"inputs"`
  11. Output *ioswitch.StreamVar `json:"output"`
  12. Length int64 `json:"length"`
  13. }
  14. func (o *Join) Execute(ctx context.Context, sw *ioswitch.Switch) error {
  15. err := ioswitch.BindArrayVars(sw, ctx, o.Inputs)
  16. if err != nil {
  17. return err
  18. }
  19. var strReaders []io.Reader
  20. for _, s := range o.Inputs {
  21. strReaders = append(strReaders, s.Stream)
  22. }
  23. defer func() {
  24. for _, str := range o.Inputs {
  25. str.Stream.Close()
  26. }
  27. }()
  28. fut := future.NewSetVoid()
  29. o.Output.Stream = io2.AfterReadClosedOnce(io2.Length(io2.Join(strReaders), o.Length), func(closer io.ReadCloser) {
  30. fut.SetVoid()
  31. })
  32. sw.PutVars(o.Output)
  33. return fut.Wait(ctx)
  34. }
  35. func init() {
  36. OpUnion.AddT((*Join)(nil))
  37. }

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