Help us shape the future of Go! Take the 2026 Go Developer Survey

ioutil

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2022 License: BSD-3-Clause Imports: 4 Imported by: 52

README

go-ioutil

Go package for creating instances 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.

Documentation

Go Reference

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()
}	

Error handling removed for brevity.

See also

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`.

func (*ReadSeekCloser) Seek

func (rsc *ReadSeekCloser) Seek(offset int64, whence int) (int64, error)

Seek implements the `io.Seeker` interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL