pools: Add a pool for buffers

This commit is contained in:
Tom Wiesing 2023-01-24 11:04:34 +01:00
parent a63bb2f669
commit 598de5b289
No known key found for this signature in database
6 changed files with 56 additions and 28 deletions

View file

@ -1,12 +1,12 @@
package environment
import (
"bytes"
"context"
"io"
"io/fs"
"os"
"github.com/FAU-CDI/wisski-distillery/pkg/pools"
"github.com/tkw1536/goprogram/stream"
)
@ -60,8 +60,10 @@ func ReadFile(env Environment, path string) ([]byte, error) {
defer file.Close()
// copy everything into a buffer!
var buffer bytes.Buffer
if _, err := io.Copy(&buffer, file); err != nil {
buffer := pools.GetBuffer()
defer pools.ReleaseBuffer(buffer)
if _, err := io.Copy(buffer, file); err != nil {
return nil, err
}