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_split.go 1.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package ops
  2. import (
  3. "io"
  4. "sync"
  5. "gitlink.org.cn/cloudream/common/utils/io2"
  6. "gitlink.org.cn/cloudream/storage/common/pkgs/ioswitch"
  7. )
  8. type ChunkedSplit struct {
  9. InputID ioswitch.StreamID `json:"inputID"`
  10. OutputIDs []ioswitch.StreamID `json:"outputIDs"`
  11. ChunkSize int `json:"chunkSize"`
  12. StreamCount int `json:"streamCount"`
  13. PaddingZeros bool `json:"paddingZeros"`
  14. }
  15. func (o *ChunkedSplit) Execute(sw *ioswitch.Switch, planID ioswitch.PlanID) error {
  16. str, err := sw.WaitStreams(planID, o.InputID)
  17. if err != nil {
  18. return err
  19. }
  20. defer str[0].Stream.Close()
  21. wg := sync.WaitGroup{}
  22. outputs := io2.ChunkedSplit(str[0].Stream, o.ChunkSize, o.StreamCount, io2.ChunkedSplitOption{
  23. PaddingZeros: o.PaddingZeros,
  24. })
  25. for i := range outputs {
  26. wg.Add(1)
  27. sw.StreamReady(planID, ioswitch.NewStream(
  28. o.OutputIDs[i],
  29. io2.AfterReadClosedOnce(outputs[i], func(closer io.ReadCloser) {
  30. wg.Done()
  31. }),
  32. ))
  33. }
  34. wg.Wait()
  35. return nil
  36. }
  37. func init() {
  38. OpUnion.AddT((*ChunkedSplit)(nil))
  39. }

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