io.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // Package io provides the Chrome DevTools Protocol
  2. // commands, types, and events for the IO domain.
  3. //
  4. // Input/Output operations for streams produced by DevTools.
  5. //
  6. // Generated by the cdproto-gen command.
  7. package io
  8. // Code generated by cdproto-gen. DO NOT EDIT.
  9. import (
  10. "context"
  11. "github.com/chromedp/cdproto/cdp"
  12. "github.com/chromedp/cdproto/runtime"
  13. )
  14. // CloseParams close the stream, discard any temporary backing storage.
  15. type CloseParams struct {
  16. Handle StreamHandle `json:"handle"` // Handle of the stream to close.
  17. }
  18. // Close close the stream, discard any temporary backing storage.
  19. //
  20. // See: https://chromedevtools.github.io/devtools-protocol/tot/IO#method-close
  21. //
  22. // parameters:
  23. //
  24. // handle - Handle of the stream to close.
  25. func Close(handle StreamHandle) *CloseParams {
  26. return &CloseParams{
  27. Handle: handle,
  28. }
  29. }
  30. // Do executes IO.close against the provided context.
  31. func (p *CloseParams) Do(ctx context.Context) (err error) {
  32. return cdp.Execute(ctx, CommandClose, p, nil)
  33. }
  34. // ReadParams read a chunk of the stream.
  35. type ReadParams struct {
  36. Handle StreamHandle `json:"handle"` // Handle of the stream to read.
  37. Offset int64 `json:"offset,omitempty"` // Seek to the specified offset before reading (if not specified, proceed with offset following the last read). Some types of streams may only support sequential reads.
  38. Size int64 `json:"size,omitempty"` // Maximum number of bytes to read (left upon the agent discretion if not specified).
  39. }
  40. // Read read a chunk of the stream.
  41. //
  42. // See: https://chromedevtools.github.io/devtools-protocol/tot/IO#method-read
  43. //
  44. // parameters:
  45. //
  46. // handle - Handle of the stream to read.
  47. func Read(handle StreamHandle) *ReadParams {
  48. return &ReadParams{
  49. Handle: handle,
  50. }
  51. }
  52. // WithOffset seek to the specified offset before reading (if not specified,
  53. // proceed with offset following the last read). Some types of streams may only
  54. // support sequential reads.
  55. func (p ReadParams) WithOffset(offset int64) *ReadParams {
  56. p.Offset = offset
  57. return &p
  58. }
  59. // WithSize maximum number of bytes to read (left upon the agent discretion
  60. // if not specified).
  61. func (p ReadParams) WithSize(size int64) *ReadParams {
  62. p.Size = size
  63. return &p
  64. }
  65. // ReadReturns return values.
  66. type ReadReturns struct {
  67. Base64encoded bool `json:"base64Encoded,omitempty"` // Set if the data is base64-encoded
  68. Data string `json:"data,omitempty"` // Data that were read.
  69. EOF bool `json:"eof,omitempty"` // Set if the end-of-file condition occurred while reading.
  70. }
  71. // Do executes IO.read against the provided context.
  72. //
  73. // returns:
  74. //
  75. // data - Data that were read.
  76. // eof - Set if the end-of-file condition occurred while reading.
  77. func (p *ReadParams) Do(ctx context.Context) (data string, eof bool, err error) {
  78. // execute
  79. var res ReadReturns
  80. err = cdp.Execute(ctx, CommandRead, p, &res)
  81. if err != nil {
  82. return "", false, err
  83. }
  84. return res.Data, res.EOF, nil
  85. }
  86. // ResolveBlobParams return UUID of Blob object specified by a remote object
  87. // id.
  88. type ResolveBlobParams struct {
  89. ObjectID runtime.RemoteObjectID `json:"objectId"` // Object id of a Blob object wrapper.
  90. }
  91. // ResolveBlob return UUID of Blob object specified by a remote object id.
  92. //
  93. // See: https://chromedevtools.github.io/devtools-protocol/tot/IO#method-resolveBlob
  94. //
  95. // parameters:
  96. //
  97. // objectID - Object id of a Blob object wrapper.
  98. func ResolveBlob(objectID runtime.RemoteObjectID) *ResolveBlobParams {
  99. return &ResolveBlobParams{
  100. ObjectID: objectID,
  101. }
  102. }
  103. // ResolveBlobReturns return values.
  104. type ResolveBlobReturns struct {
  105. UUID string `json:"uuid,omitempty"` // UUID of the specified Blob.
  106. }
  107. // Do executes IO.resolveBlob against the provided context.
  108. //
  109. // returns:
  110. //
  111. // uuid - UUID of the specified Blob.
  112. func (p *ResolveBlobParams) Do(ctx context.Context) (uuid string, err error) {
  113. // execute
  114. var res ResolveBlobReturns
  115. err = cdp.Execute(ctx, CommandResolveBlob, p, &res)
  116. if err != nil {
  117. return "", err
  118. }
  119. return res.UUID, nil
  120. }
  121. // Command names.
  122. const (
  123. CommandClose = "IO.close"
  124. CommandRead = "IO.read"
  125. CommandResolveBlob = "IO.resolveBlob"
  126. )