Documentation
¶
Overview ¶
Edit! This Gosh fork includes a modifed copy of of Distin H's buffered io pipes package and the corresponding buffer package on github, both have the same license and copyright. Awesome program, highly recommend. I did this so goshworker could just use the gosh exec api without extrenal dependencies exernal dependiencies other custom than channels which will be for greater memory and task management later, while keeping this version of gosh standard libary compliant.
The MIT License (MIT)
Copyright (c) 2015 Dustin H ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Index ¶
- func Copy(dst io.Writer, src io.Reader, buf Buffer) (n int64, err error)
- func Empty(buf Buffer) bool
- func Full(buf Buffer) bool
- func Gap(buf Buffer) int64
- func LimitWriter(w io.Writer, n int64) io.Writer
- func NewReader(src io.Reader, buf Buffer) io.ReadCloser
- func Pipe(buf Buffer) (r *PipeReader, w *PipeWriter)
- func ReaderFromByteSlice(bats []byte) io.Reader
- func ReaderFromChanByteSlice(ch chan []byte) io.Reader
- func ReaderFromChanReadonlyByteSlice(ch <-chan []byte) io.Reader
- func ReaderFromChanReadonlyString(ch <-chan string) io.Reader
- func ReaderFromChanString(ch chan string) io.Reader
- func ReaderFromInterface(x interface{}) io.Reader
- func ReaderFromString(str string) io.Reader
- func Wrap(w DoerAt, p []byte, off int64, wrapAt int64) (n int, err error)
- func WriterFromInterface(x interface{}) io.Writer
- func WriterToChanByteSlice(ch chan<- []byte) io.Writer
- func WriterToChanString(ch chan<- string) io.Writer
- type Buffer
- type BufferAt
- type DoAtFunc
- type DoerAt
- type File
- type List
- type PipeReader
- type PipeWriter
- type Pool
- type ReadWriterAt
- type ReaderUnrefinableFromInterface
- type WrapReader
- type WrapWriter
- type Wrapper
- func (wpr *Wrapper) Cap() int64
- func (wpr *Wrapper) Len() int64
- func (wpr *Wrapper) Read(p []byte) (n int, err error)
- func (wpr *Wrapper) ReadAt(p []byte, off int64) (n int, err error)
- func (wpr *Wrapper) Reset()
- func (wpr *Wrapper) SetReadWriterAt(rwa ReadWriterAt)
- func (wpr *Wrapper) Write(p []byte) (n int, err error)
- func (wpr *Wrapper) WriteAt(p []byte, off int64) (n int, err error)
- type WriterUnrefinableFromInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Copy ¶
Copy copies from src to buf, and from buf to dst in parallel until either EOF is reached on src or an error occurs. It returns the number of bytes copied to dst and the first error encountered while copying, if any. EOF is not considered to be an error. If src implements WriterTo, it is used to write to the supplied Buffer. If dst implements ReaderFrom, it is used to read from the supplied Buffer.
func LimitWriter ¶
LimitWriter works like io.LimitReader. It writes at most n bytes to the underlying Writer. It returns io.ErrShortWrite if more than n bytes are attempted to be written.
func NewReader ¶
func NewReader(src io.Reader, buf Buffer) io.ReadCloser
NewReader reads from the buffer which is concurrently filled with data from the passed src.
func Pipe ¶
func Pipe(buf Buffer) (r *PipeReader, w *PipeWriter)
Pipe creates a buffered pipe. It can be used to connect code expecting an io.Reader with code expecting an io.Writer. Reads on one end read from the supplied Buffer. Writes write to the supplied Buffer. It is safe to call Read and Write in parallel with each other or with Close. Close will complete once pending I/O is done, and may cancel blocking Read/Writes. Buffered data will still be available to Read after the Writer has been closed. Parallel calls to Read, and parallel calls to Write are also safe : the individual calls will be gated sequentially.
func ReaderFromByteSlice ¶
func ReaderFromChanByteSlice ¶
func ReaderFromChanString ¶
func ReaderFromInterface ¶
Converts any of a range of data sources to an io.Reader interface, or an io.ReadCloser if appropriate.
Readers will be produced from:
string []byte io.Reader bytes.Buffer <-chan string <-chan []byte
ReadClosers will be produced from:
chan string chan []byte
An error of type ReaderUnrefinableFromInterface is thrown if an argument of any other type is given.
func ReaderFromString ¶
func Wrap ¶
Wrap causes an action on an array of bytes (like read/write) to be done from an offset off, wrapping at offset wrapAt.
func WriterFromInterface ¶
Converts any of a range of data sinks to an io.Writer interface, or an io.WriteCloser if appropriate.
Writers will be produced from:
io.Writer bytes.Buffer
WriteClosers will be produced from:
<-chan string chan string <-chan []byte chan []byte
An error of type WriterUnrefinableFromInterface is thrown if an argument of any other type is given.
func WriterToChanByteSlice ¶
func WriterToChanString ¶
Types ¶
type Buffer ¶
type Buffer interface {
Len() int64 // How much data is Buffered in bytes
Cap() int64 // How much data can be Buffered at once in bytes.
io.Reader // Read() will read from the top of the buffer [io.EOF if empty]
io.Writer // Write() will write to the end of the buffer [io.ErrShortWrite if not enough space]
Reset() // Truncates the buffer, Len() == 0.
}
var Discard Buffer = discard{}
Discard is a Buffer which writes to ioutil.Discard and read's return 0, io.EOF. All of its methods are concurrent safe.
func NewMulti ¶
NewMulti returns a Buffer which is the logical concatenation of the passed buffers. The data in the buffers is shifted such that there is no non-empty buffer following a non-full buffer, this process is also run after every Read. If no buffers are passed, the returned Buffer is nil.
func NewPartition ¶
NewPartition returns a Buffer which uses a Pool to extend or shrink its size as needed. It automatically allocates new buffers with pool.Get() to extend is length, and pool.Put() to release unused buffers as it shrinks.
func NewRing ¶
NewRing returns a Ring Buffer from a BufferAt. It overwrites old data in the Buffer when needed (when its full).
func NewSpill ¶
NewSpill returns a Buffer which writes data to w when there's an error writing to buf. Such as when buf is full, or the disk is full, etc.
func NewSwap ¶
NewSwap creates a Buffer which writes to a until you write past a.Cap() then it io.Copy's from a to b and writes to b. Once the Buffer is empty again, it starts over writing to a. Note that if b.Cap() <= a.Cap() it will cause a panic, b is expected to be larger in order to accomodate writes past a.Cap().
func NewUnboundedBuffer ¶
NewUnboundedBuffer returns a Buffer which buffers "mem" bytes to memory and then creates file's of size "file" to buffer above "mem" bytes.
type BufferAt ¶
BufferAt is a buffer which supports io.ReaderAt and io.WriterAt
func NewMultiAt ¶
NewMultiAt returns a BufferAt which is the logical concatenation of the passed BufferAts. The data in the buffers is shifted such that there is no non-empty buffer following a non-full buffer, this process is also run after every Read. If no buffers are passed, the returned Buffer is nil.
func NewSwapAt ¶
NewSwapAt creates a BufferAt which writes to a until you write past a.Cap() then it io.Copy's from a to b and writes to b. Once the Buffer is empty again, it starts over writing to a. Note that if b.Cap() <= a.Cap() it will cause a panic, b is expected to be larger in order to accomodate writes past a.Cap().
type List ¶
type List []Buffer
type PipeReader ¶
type PipeReader struct {
// contains filtered or unexported fields
}
func (*PipeReader) Close ¶
func (r *PipeReader) Close() error
Close closes the reader; subsequent writes to the write half of the pipe will return the error io.ErrClosedPipe.
func (*PipeReader) CloseWithError ¶
func (r *PipeReader) CloseWithError(err error) error
CloseWithError closes the reader; subsequent writes to the write half of the pipe will return the error err.
type PipeWriter ¶
type PipeWriter struct {
// contains filtered or unexported fields
}
A PipeWriter is the write half of a pipe.
func (*PipeWriter) Close ¶
func (w *PipeWriter) Close() error
Close closes the writer; once the buffer is empty subsequent reads from the read half of the pipe will return no bytes and io.EOF after all the buffer has been read. CloseWithError always returns nil.
func (*PipeWriter) CloseWithError ¶
func (w *PipeWriter) CloseWithError(err error) error
CloseWithError closes the writer; once the buffer is empty subsequent reads from the read half of the pipe will return no bytes and the error err, or io.EOF if err is nil. CloseWithError always returns nil.
type Pool ¶
type Pool interface {
Get() (Buffer, error) // Allocate a Buffer
Put(buf Buffer) error // Release or Reuse a Buffer
}
func NewFilePool ¶
NewFilePool returns a Pool, Get() returns a file-based buffer of max size N. Put() closes and deletes the underlying file for the buffer. Get() may return an error if it fails to create a file for the buffer. Put() may return an error if it fails to delete the file.
func NewMemPool ¶
NewMemPool returns a Pool, Get() returns an in memory buffer of max size N. Put() returns the buffer to the pool after resetting it. Get() and Put() errors will always be nil.
type ReadWriterAt ¶
ReadWriterAt implements io.ReaderAt and io.WriterAt
type ReaderUnrefinableFromInterface ¶
type ReaderUnrefinableFromInterface struct {
// contains filtered or unexported fields
}
Error raised by ReaderFromInterface() when is called with an argument of an unexpected type.
func (ReaderUnrefinableFromInterface) Error ¶
func (err ReaderUnrefinableFromInterface) Error() string
type WrapReader ¶
type WrapReader struct {
// contains filtered or unexported fields
}
WrapReader wraps reads around a section of data.
func NewWrapReader ¶
func NewWrapReader(r io.ReaderAt, off int64, wrapAt int64) *WrapReader
NewWrapReader creates a WrapReader starting at offset off, and wrapping at offset wrapAt.
func (*WrapReader) Read ¶
func (r *WrapReader) Read(p []byte) (n int, err error)
Read reads into p starting at the current offset, wrapping if it reaches the end. The current offset is shifted forward by the amount read.
type WrapWriter ¶
type WrapWriter struct {
// contains filtered or unexported fields
}
WrapWriter wraps writes around a section of data.
func NewWrapWriter ¶
func NewWrapWriter(w io.WriterAt, off int64, wrapAt int64) *WrapWriter
NewWrapWriter creates a WrapWriter starting at offset off, and wrapping at offset wrapAt.
type Wrapper ¶
type Wrapper struct {
// N is the offset at which to "wrap" back to the start
N int64
// L is the length of the data written
L int64
// O is our offset in the data
O int64
// contains filtered or unexported fields
}
Wrapper implements a io.ReadWriter and ReadWriterAt such that when reading/writing goes past N bytes, it "wraps" back to the beginning.
func NewWrapper ¶
func NewWrapper(rwa ReadWriterAt, L, O, N int64) *Wrapper
NewWrapper creates a Wrapper based on ReadWriterAt rwa. L is the current length, O is the current offset, and N is offset at which we "wrap".
func (*Wrapper) Reset ¶
func (wpr *Wrapper) Reset()
Reset seeks to the start (0 offset), and sets the length to 0.
func (*Wrapper) SetReadWriterAt ¶
func (wpr *Wrapper) SetReadWriterAt(rwa ReadWriterAt)
SetReadWriterAt lets you switch the underlying Read/WriterAt
type WriterUnrefinableFromInterface ¶
type WriterUnrefinableFromInterface struct {
// contains filtered or unexported fields
}
Error raised by WriterFromInterface() when is called with an argument of an unexpected type.
func (WriterUnrefinableFromInterface) Error ¶
func (err WriterUnrefinableFromInterface) Error() string