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.

length.go 772 B

123456789101112131415161718192021222324252627282930313233343536
  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 Length struct {
  10. Input *ioswitch.StreamVar `json:"input"`
  11. Output *ioswitch.StreamVar `json:"output"`
  12. Length int64 `json:"length"`
  13. }
  14. func (o *Length) Execute(ctx context.Context, sw *ioswitch.Switch) error {
  15. err := sw.BindVars(ctx, o.Input)
  16. if err != nil {
  17. return err
  18. }
  19. defer o.Input.Stream.Close()
  20. fut := future.NewSetVoid()
  21. o.Output.Stream = io2.AfterReadClosedOnce(io2.Length(o.Input.Stream, o.Length), func(closer io.ReadCloser) {
  22. fut.SetVoid()
  23. })
  24. sw.PutVars(o.Output)
  25. return fut.Wait(ctx)
  26. }
  27. func init() {
  28. OpUnion.AddT((*Length)(nil))
  29. }

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