Added buffer
This commit is contained in:
parent
40707e4cbb
commit
74afda5110
1 changed files with 22 additions and 0 deletions
22
buffer.go
Normal file
22
buffer.go
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue