Documentation
¶
Overview ¶
package ioutil provides methods for creating a new instance conforming to the Go 1.16 io.ReadSeekCloser interface from a variety of io.Read* instances that implement some but not all of the io.Reader, io.Seeker and io.Closer interfaces.
Example
import (
"bytes"
"github.com/whosonfirst/go-ioutil"
"io"
"log"
)
func main(){
fh, _ := os.Open("README.md")
rsc, _ := NewReadSeekCloser(fh)
body, _ := io.ReadAll(rsc)
rsc.Seek(0, 0)
body2, _ := io.ReadAll(rsc)
same := bytes.Equal(body, body2)
log.Printf("Same %t\n", same)
rsc.Close()
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewReadSeekCloser ¶
func NewReadSeekCloser(fh interface{}) (io.ReadSeekCloser, error)
Create a new NewReadSeekCloser instance conforming to the Go 1.16 `io.ReadSeekCloser` interface. This method accepts the following types: io.ReadSeekCloser, io.Reader, io.ReadCloser and io.ReadSeeker.
Types ¶
type ReadSeekCloser ¶
type ReadSeekCloser struct {
io.Reader
io.Seeker
io.Closer
// contains filtered or unexported fields
}
Type ReadSeekCloser implements the io.Reader, io.Seeker and io.Closer interfaces.
func (*ReadSeekCloser) Close ¶
func (rsc *ReadSeekCloser) Close() error
Close closes the reader; subsequent writes to the write half of the pipe will return the error `io.ErrClosedPipe`.
func (*ReadSeekCloser) Read ¶
func (rsc *ReadSeekCloser) Read(p []byte) (n int, err error)
Read implements the standard Read interface: it reads data from the pipe, blocking until a writer arrives or the write end is closed. If the write end is closed with an error, that error is returned as err; otherwise err is `io.EOF`.