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

Function writeFileFromReader

run.go:552–573  ·  view source on GitHub ↗

writeFileFromReader writes the contents of r to diskPath, creating parent directories as needed and preserving the executable bit on non-Windows hosts.

(diskPath string, r io.Reader, mode os.FileMode)

Source from the content-addressed store, hash-verified

550// writeFileFromReader writes the contents of r to diskPath, creating parent
551// directories as needed and preserving the executable bit on non-Windows hosts.
552func writeFileFromReader(diskPath string, r io.Reader, mode os.FileMode) error {
553 if err := os.MkdirAll(filepath.Dir(diskPath), 0o777); err != nil {
554 return fmt.Errorf("could not create directory: %w", err)
555 }
556 outFile, err := os.Create(diskPath)
557 if err != nil {
558 return fmt.Errorf("could not create file: %w", err)
559 }
560 if _, err := io.Copy(outFile, r); err != nil {
561 outFile.Close() //nolint:errcheck
562 return fmt.Errorf("could not write file: %w", err)
563 }
564 if err := outFile.Close(); err != nil {
565 return fmt.Errorf("could not close file: %w", err)
566 }
567 if mode.Perm()&0o100 != 0 && runtime.GOOS != "windows" {
568 if err := makeFileExecutable(diskPath); err != nil {
569 return err
570 }
571 }
572 return nil
573}
574
575// extractTarGzEntry extracts a single named entry from a gzipped tar archive to
576// diskPath and marks it executable.

Callers 3

extractTarGzEntryFunction · 0.85
extractZipEntryFunction · 0.85

Calls 5

makeFileExecutableFunction · 0.85
ErrorfMethod · 0.80
CopyMethod · 0.80
CreateMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected