Added buffer

This commit is contained in:
Leon Mika 2026-08-08 10:24:53 +10:00
parent 40707e4cbb
commit 74afda5110

22
buffer.go Normal file
View file

@ -0,0 +1,22 @@
package scriptx
import (
"bytes"
"io"
)
// Buffer will read the contents of the source in an internal buffer until an EOF is encountered.
// It will then write the entire contents of the buffer to the writer. Useful when reading and
// writing to the same file.
func Buffer() func(r io.Reader, w io.Writer) error {
return func(r io.Reader, w io.Writer) error {
var bfr bytes.Buffer
if _, err := io.Copy(&bfr, r); err != nil {
return err
}
if _, err := io.Copy(w, &bfr); err != nil {
return err
}
return nil
}
}