|
- package ops2
-
- import (
- "context"
- "io"
-
- "gitlink.org.cn/cloudream/common/pkgs/future"
- "gitlink.org.cn/cloudream/common/pkgs/ioswitch/exec"
- "gitlink.org.cn/cloudream/common/utils/io2"
- )
-
- func init() {
- // OpUnion.AddT((*Length)(nil))
- }
-
- type Length struct {
- Input *exec.StreamVar `json:"input"`
- Output *exec.StreamVar `json:"output"`
- Length int64 `json:"length"`
- }
-
- func (o *Length) Execute(ctx context.Context, e *exec.Executor) error {
- err := e.BindVars(ctx, o.Input)
- if err != nil {
- return err
- }
- defer o.Input.Stream.Close()
-
- fut := future.NewSetVoid()
- o.Output.Stream = io2.AfterReadClosedOnce(io2.Length(o.Input.Stream, o.Length), func(closer io.ReadCloser) {
- fut.SetVoid()
- })
- e.PutVars(o.Output)
-
- return fut.Wait(ctx)
- }
|