iowrap

package
v4.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: Apache-2.0 Imports: 2 Imported by: 21

Documentation

Overview

Package iowrap's Pipe Inspired by following project: - golang stdlib: io.Pipe and bytes.Buffer - https://github.com/djherbis/nio

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pipe

func Pipe() (r *PipeReader, w *PipeWriter)

Pipe creates a synchronous in-memory pipe. It can be used to connect code expecting an io.Reader with code expecting an io.Writer.

NOTES:

  • PipeReader and PipeWriter is not thread safe
  • Internal buffer will never be grow up, so write could be block while no space to write.

Types

type CallbackifyReadCloser

type CallbackifyReadCloser struct {
	// contains filtered or unexported fields
}

CallbackifyReadCloser will execute callback func in Read.

func CallbackReadCloser

func CallbackReadCloser(r io.ReadCloser, fn func([]byte)) *CallbackifyReadCloser

CallbackReadCloser will create a new CallbackifyReadCloser.

func (*CallbackifyReadCloser) Close

func (r *CallbackifyReadCloser) Close() error

Close will close underlying Reader.

func (*CallbackifyReadCloser) Read

func (r *CallbackifyReadCloser) Read(p []byte) (int, error)

Read will read from underlying Reader.

type CallbackifyReader

type CallbackifyReader struct {
	// contains filtered or unexported fields
}

CallbackifyReader will execute callback func in Read.

func CallbackReader

func CallbackReader(r io.Reader, fn func([]byte)) *CallbackifyReader

CallbackReader will create a new CallbackifyReader.

func (*CallbackifyReader) Read

func (r *CallbackifyReader) Read(p []byte) (int, error)

Read will read from underlying Reader.

type CallbackifyWriter

type CallbackifyWriter struct {
	// contains filtered or unexported fields
}

CallbackifyWriter will execute callback func in Write.

func CallbackWriter

func CallbackWriter(w io.Writer, fn func([]byte)) *CallbackifyWriter

CallbackWriter will create a new CallbackifyWriter.

func (*CallbackifyWriter) Write

func (w *CallbackifyWriter) Write(p []byte) (int, error)

Write will write into underlying Writer.

type LimitedReadCloser

type LimitedReadCloser struct {
	// contains filtered or unexported fields
}

LimitedReadCloser hasCall from underlying r and provide Close as well.

func LimitReadCloser

func LimitReadCloser(r io.ReadCloser, n int64) *LimitedReadCloser

LimitReadCloser will return a limited hasCall closer.

func (*LimitedReadCloser) Close

func (l *LimitedReadCloser) Close() error

Close will close underlying reader.

func (*LimitedReadCloser) Read

func (l *LimitedReadCloser) Read(p []byte) (n int, err error)

Read is copied from io.LimitedReader's Read.

type PipeReader

type PipeReader struct {
	// contains filtered or unexported fields
}

func (*PipeReader) Close

func (r *PipeReader) Close() error

func (*PipeReader) CloseWithError

func (r *PipeReader) CloseWithError(err error)

func (*PipeReader) Read

func (r *PipeReader) Read(p []byte) (n int, err error)

type PipeWriter

type PipeWriter struct {
	// contains filtered or unexported fields
}

func (*PipeWriter) Close

func (w *PipeWriter) Close() error

func (*PipeWriter) CloseWithError

func (w *PipeWriter) CloseWithError(err error)

func (*PipeWriter) Write

func (w *PipeWriter) Write(p []byte) (n int, err error)

type ReadAtCloser

type ReadAtCloser interface {
	io.Closer
	io.ReaderAt
}

ReadAtCloser is the composition of io.Closer and io.ReaderAt

type SectionedReadCloser

type SectionedReadCloser struct {
	// contains filtered or unexported fields
}

SectionedReadCloser hasCall from underlying r and provide Close as well.

func SectionReadCloser

func SectionReadCloser(r ReadAtCloser, off, n int64) *SectionedReadCloser

SectionReadCloser will return a sectioned hasCall closer.

func (*SectionedReadCloser) Close

func (s *SectionedReadCloser) Close() error

Close will close underlying reader.

func (*SectionedReadCloser) Read

func (s *SectionedReadCloser) Read(p []byte) (n int, err error)

Read is copied from io.SectionReader's Read.

type SeekCloseableReader

type SeekCloseableReader struct {
	// contains filtered or unexported fields
}

SeekCloseableReader represents a reader that can also delegate io.Seeker and io.Closer interfaces to the underlying object if they are available.

func ReadSeekCloser

func ReadSeekCloser(r io.Reader) *SeekCloseableReader

ReadSeekCloser wraps a io.Reader returning a SeekCloseableReader. Allows the SDK to accept an io.Reader that is not also an io.Seeker for unsigned streaming payload API operations.

A ReadSeekCloser wrapping an nonseekable io.Reader used in an API operation's input will prevent that operation being retried in the case of network errors, and cause operation requests to fail if the operation requires payload signing.

NOTES: Idea borrows from AWS Go SDK.

func SizedReadSeekCloser

func SizedReadSeekCloser(r io.Reader, size int64) *SeekCloseableReader

SizedReadSeekCloser will return a size featured SeekCloseableReader.

func (*SeekCloseableReader) Close

func (r *SeekCloseableReader) Close() error

Close closes the SeekCloseableReader.

If the SeekCloseableReader is not an io.Closer nothing will be done.

func (*SeekCloseableReader) Read

func (r *SeekCloseableReader) Read(p []byte) (int, error)

Read reads from the reader up to size of p. The number of bytes read, and error if it occurred will be returned.

If the reader is not an io.Reader zero bytes read, and nil error will be returned.

Performs the same functionality as io.Reader Read

func (*SeekCloseableReader) Seek

func (r *SeekCloseableReader) Seek(offset int64, whence int) (int64, error)

Seek sets the offset for the next Read to offset, interpreted according to whence: 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end. Seek returns the new offset and an error, if any.

If the SeekCloseableReader is not an io.Seeker nothing will be done to underlying Reader. For example: seek to end and then seek current will still return 0.

Jump to

Keyboard shortcuts

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