zerocopy

package module
v0.0.0-...-b79589c Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2014 License: CC0-1.0 Imports: 7 Imported by: 0

README

zerocopy

A zero-copy Reader interface, which returns a byte slice pointing at the underlying memory rather than copying it to you.

Documentation

Zero copy streams of *bytes.Reader and *os.File.

These are inherently unsafe since we violate the laws of the language to obtain access to the underlying byte slice of the *bytes.Reader.

It's all in good fun, though?

Caveat Emptor.

Documentation

Overview

zerocopy.Reader gives a reading interface for a byte slice or a file, which doesn't make a copy of the underlying byte slice. To achieve this, a new "Read" interface is required, where the data storage is not specified by the caller, but by the callee. This is so that the implementation is at liberty to return a byte slice

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ReadCloser

type ReadCloser interface {
	Reader
	Close() error
}

func NewReader

func NewReader(r io.Reader) (ReadCloser, error)

Construct a new Zero-Copy reader on `r`. `r` must be an *os.File or a *bytes.Reader, otherwise an error is returned.

func NewReaderFromBytes

func NewReaderFromBytes(b []byte) (ReadCloser, error)

Helper to construct a zero-copy reader directly from a byte slice.

type Reader

type Reader interface {
	// Read `size` bytes from the underlying stream, and return a byte slice
	// to those bytes. The returned []byte is a slice which references the
	// underlying bytes, and must not be written to.
	Read(size uint64) ([]byte, error)
}

The zero-copy Reader interface. It has a different Read() method than the usual because the semantics are different.

Jump to

Keyboard shortcuts

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