mirror of
https://github.com/playwright-community/playwright-go.git
synced 2026-06-03 21:02:27 +08:00
Some checks failed
Go / Lint (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (chromium, oldstable, macos-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (chromium, oldstable, ubuntu-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (chromium, oldstable, windows-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (chromium, stable, macos-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (chromium, stable, ubuntu-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (chromium, stable, windows-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (firefox, oldstable, macos-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (firefox, oldstable, ubuntu-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (firefox, oldstable, windows-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (firefox, stable, macos-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (firefox, stable, ubuntu-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (firefox, stable, windows-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (webkit, oldstable, macos-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (webkit, oldstable, ubuntu-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (webkit, oldstable, windows-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (webkit, stable, macos-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (webkit, stable, ubuntu-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (webkit, stable, windows-latest) (push) Has been cancelled
Go / test-examples (push) Has been cancelled
Docs / Deploy docs (push) Has been cancelled
Verify Types / verify (push) Has been cancelled
Go / finish (push) Has been cancelled
69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
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]any{"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]any{"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]any) *streamImpl {
|
|
stream := &streamImpl{}
|
|
stream.createChannelOwner(stream, parent, objectType, guid, initializer)
|
|
return stream
|
|
}
|