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.

drop.go 1.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package ops
  2. import (
  3. "fmt"
  4. "io"
  5. "gitlink.org.cn/cloudream/common/pkgs/ioswitch/dag"
  6. "gitlink.org.cn/cloudream/common/pkgs/ioswitch/exec"
  7. )
  8. func init() {
  9. exec.UseOp[*DropStream]()
  10. }
  11. type DropStream struct {
  12. Input exec.VarID `json:"input"`
  13. }
  14. func (o *DropStream) Execute(ctx *exec.ExecContext, e *exec.Executor) error {
  15. str, err := exec.BindVar[*exec.StreamValue](e, ctx.Context, o.Input)
  16. if err != nil {
  17. return err
  18. }
  19. defer str.Stream.Close()
  20. for {
  21. buf := make([]byte, 1024*8)
  22. _, err = str.Stream.Read(buf)
  23. if err == io.EOF {
  24. return nil
  25. }
  26. if err != nil {
  27. return err
  28. }
  29. }
  30. }
  31. func (o *DropStream) String() string {
  32. return fmt.Sprintf("DropStream %v", o.Input)
  33. }
  34. type DropNode struct {
  35. dag.NodeBase
  36. }
  37. func (b *GraphNodeBuilder) NewDropStream() *DropNode {
  38. node := &DropNode{}
  39. b.AddNode(node)
  40. return node
  41. }
  42. func (t *DropNode) SetInput(v *dag.Var) {
  43. t.InputStreams().EnsureSize(1)
  44. v.StreamTo(t, 0)
  45. }
  46. func (t *DropNode) GenerateOp() (exec.Op, error) {
  47. return &DropStream{
  48. Input: t.InputStreams().Get(0).VarID,
  49. }, nil
  50. }
  51. // func (t *DropType) String(node *dag.Node) string {
  52. // return fmt.Sprintf("Drop[]%v%v", formatStreamIO(node), formatValueIO(node))
  53. // }