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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package ops
  2. import (
  3. "context"
  4. "fmt"
  5. "io"
  6. "gitlink.org.cn/cloudream/common/pkgs/ioswitch/dag"
  7. "gitlink.org.cn/cloudream/common/pkgs/ioswitch/exec"
  8. )
  9. func init() {
  10. exec.UseOp[*DropStream]()
  11. }
  12. type DropStream struct {
  13. Input *exec.StreamVar `json:"input"`
  14. }
  15. func (o *DropStream) Execute(ctx context.Context, e *exec.Executor) error {
  16. err := e.BindVars(ctx, o.Input)
  17. if err != nil {
  18. return err
  19. }
  20. for {
  21. buf := make([]byte, 1024*8)
  22. _, err = o.Input.Stream.Read(buf)
  23. if err == io.EOF {
  24. return nil
  25. }
  26. if err != nil {
  27. return err
  28. }
  29. }
  30. }
  31. type DropType struct{}
  32. func (t *DropType) InitNode(node *dag.Node) {
  33. dag.NodeDeclareInputStream(node, 1)
  34. }
  35. func (t *DropType) GenerateOp(op *dag.Node) (exec.Op, error) {
  36. return &DropStream{
  37. Input: op.InputStreams[0].Var,
  38. }, nil
  39. }
  40. func (t *DropType) String(node *dag.Node) string {
  41. return fmt.Sprintf("Drop[]%v%v", formatStreamIO(node), formatValueIO(node))
  42. }