diff options
| author | mo khan <mo@mokhan.ca> | 2025-05-14 13:18:54 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-05-14 13:18:54 -0600 |
| commit | 4b2d609a0efcc1d9b2f1a08f954d067ad1d9cd1e (patch) | |
| tree | 0afacf9217b0569130da6b97d4197331681bf119 /vendor/github.com/playwright-community/playwright-go/stream.go | |
| parent | ab373d1fe698cd3f53258c09bc8515d88a6d0b9e (diff) | |
test: use playwright to test out an OIDC login
Diffstat (limited to 'vendor/github.com/playwright-community/playwright-go/stream.go')
| -rw-r--r-- | vendor/github.com/playwright-community/playwright-go/stream.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/vendor/github.com/playwright-community/playwright-go/stream.go b/vendor/github.com/playwright-community/playwright-go/stream.go new file mode 100644 index 0000000..e23942f --- /dev/null +++ b/vendor/github.com/playwright-community/playwright-go/stream.go @@ -0,0 +1,68 @@ +package playwright + +import ( + "bufio" + "encoding/base64" + "os" + "path/filepath" +) + +type streamImpl struct { + channelOwner +} + +func (s *streamImpl) SaveAs(path string) error { + err := os.MkdirAll(filepath.Dir(path), 0o777) + if err != nil { + return err + } + file, err := os.Create(path) + if err != nil { + return err + } + defer file.Close() + writer := bufio.NewWriter(file) + for { + binary, err := s.channel.Send("read", map[string]interface{}{"size": 1024 * 1024}) + if err != nil { + return err + } + bytes, err := base64.StdEncoding.DecodeString(binary.(string)) + if err != nil { + return err + } + if len(bytes) == 0 { + break + } + _, err = writer.Write(bytes) + if err != nil { + return err + } + } + return writer.Flush() +} + +func (s *streamImpl) ReadAll() ([]byte, error) { + var data []byte + for { + binary, err := s.channel.Send("read", map[string]interface{}{"size": 1024 * 1024}) + if err != nil { + return nil, err + } + bytes, err := base64.StdEncoding.DecodeString(binary.(string)) + if err != nil { + return nil, err + } + if len(bytes) == 0 { + break + } + data = append(data, bytes...) + } + return data, nil +} + +func newStream(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *streamImpl { + stream := &streamImpl{} + stream.createChannelOwner(stream, parent, objectType, guid, initializer) + return stream +} |
