mirror of
https://github.com/IBM/fp-go.git
synced 2025-08-10 22:31:32 +02:00
fix: small changes to readall
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
@@ -18,20 +18,23 @@ package file
|
|||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
FL "github.com/IBM/fp-go/file"
|
||||||
|
F "github.com/IBM/fp-go/function"
|
||||||
IOE "github.com/IBM/fp-go/ioeither"
|
IOE "github.com/IBM/fp-go/ioeither"
|
||||||
)
|
)
|
||||||
|
|
||||||
func onReadAll[R io.Reader](r R) IOE.IOEither[error, []byte] {
|
var (
|
||||||
return IOE.TryCatchError(func() ([]byte, error) {
|
// readAll is the adapted version of [io.ReadAll]
|
||||||
return io.ReadAll(r)
|
readAll = IOE.Eitherize1(io.ReadAll)
|
||||||
})
|
)
|
||||||
}
|
|
||||||
|
|
||||||
// ReadAll uses a generator function to create a stream, reads it and closes it
|
// ReadAll uses a generator function to create a stream, reads it and closes it
|
||||||
func ReadAll[R io.ReadCloser](acquire IOE.IOEither[error, R]) IOE.IOEither[error, []byte] {
|
func ReadAll[R io.ReadCloser](acquire IOE.IOEither[error, R]) IOE.IOEither[error, []byte] {
|
||||||
return IOE.WithResource[[]byte](
|
return F.Pipe1(
|
||||||
acquire,
|
F.Flow2(
|
||||||
Close[R])(
|
FL.ToReader[R],
|
||||||
onReadAll[R],
|
readAll,
|
||||||
|
),
|
||||||
|
IOE.WithResource[[]byte](acquire, Close[R]),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user