MCPcopy
hub / github.com/mxschmitt/playwright-go / SaveAs

Method SaveAs

stream.go:14–43  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

12}
13
14func (s *streamImpl) SaveAs(path string) error {
15 err := os.MkdirAll(filepath.Dir(path), 0o777)
16 if err != nil {
17 return err
18 }
19 file, err := os.Create(path)
20 if err != nil {
21 return err
22 }
23 defer file.Close() //nolint:errcheck
24 writer := bufio.NewWriter(file)
25 for {
26 binary, err := s.channel.Send("read", map[string]any{"size": 1024 * 1024})
27 if err != nil {
28 return err
29 }
30 bytes, err := base64.StdEncoding.DecodeString(binary.(string))
31 if err != nil {
32 return err
33 }
34 if len(bytes) == 0 {
35 break
36 }
37 _, err = writer.Write(bytes)
38 if err != nil {
39 return err
40 }
41 }
42 return writer.Flush()
43}
44
45func (s *streamImpl) ReadAll() ([]byte, error) {
46 var data []byte

Callers

nothing calls this directly

Calls 3

CreateMethod · 0.65
CloseMethod · 0.65
SendMethod · 0.65

Tested by

no test coverage detected