iohelper

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2021 License: MIT Imports: 6 Imported by: 0

README

Buffering helpers

These are asynchronous buffers to help us deal with blocking APIs. They are similar to what you would except a from a TCP transmit window.

There are two asynchronous buffer implementations. Their respective performance remains to be tested.

AsyncWriterBuffer

  • Writes to a bytes buffer
  • Asynchronously write them
  • In-transmission buffer size is precise

AsyncWriterChannel

  • Writes to a channel of bytes buffer
  • Asynchronous write them
  • In-transmission buffer size is estimated (we're not cutting write buffer into smaller chunks)

Documentation

Overview

Package iohelper should brings tools to help manage IOs

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("closed")

ErrClosed is returned if the buffer was closed

Functions

This section is empty.

Types

type AsyncWriterBuffer

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

AsyncWriterBuffer is an asynchronous writer that will push writes to a buffer and then writes them in separate goroutine.

func NewAsyncWriterBuffer

func NewAsyncWriterBuffer(writer io.WriteCloser, maxSize int) *AsyncWriterBuffer

NewAsyncWriterBuffer creates a new asynchronous buffered writer based on a standard buffer

func (*AsyncWriterBuffer) Close

func (aw *AsyncWriterBuffer) Close() error

Close flushes the buffer and closes the underlying writer

func (*AsyncWriterBuffer) Write

func (aw *AsyncWriterBuffer) Write(data []byte) (int, error)

type AsyncWriterChannel

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

AsyncWriterChannel is an asynchronous writer that will push writes to a channel and then write them in a separate goroutine.

func NewAsyncWriterChannel

func NewAsyncWriterChannel(writer io.WriteCloser, bufferSize int) *AsyncWriterChannel

NewAsyncWriterChannel creates an asynchronous buffered writer based on a channel

func (*AsyncWriterChannel) Close

func (aw *AsyncWriterChannel) Close() error

Close flushes the buffer and closes the underlying writer

func (*AsyncWriterChannel) Write

func (aw *AsyncWriterChannel) Write(src []byte) (int, error)

type BufferedWriteCloser

type BufferedWriteCloser struct {
	*bufio.Writer
	io.Closer
}

BufferedWriteCloser brings a io.Closer to the bufio.Writer

func NewBufferedWriteCloser

func NewBufferedWriteCloser(dst io.WriteCloser, size int) *BufferedWriteCloser

NewBufferedWriteCloser will create a buffered WriteCloser instance from a WriteCloser

func (*BufferedWriteCloser) Close

func (wc *BufferedWriteCloser) Close() error

Close will close the underlying stream

Jump to

Keyboard shortcuts

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