memstream

package module
v0.0.0-...-869756e Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2021 License: BSD-3-Clause Imports: 2 Imported by: 5

README

Intro

Memstream is an expandable ReadWriteSeeker for Golang that works with an internally managed byte buffer. Operation is usage is intended to be seamless and smooth.

In situations where the maximum read/write sizes are known, a fixed []byte/byte buffer will likely offer better performance.

Docs

As with all Go packages, documentation can be found on godoc.org.

Install

 $ go get github.com/traherom/memstream

Documentation

Overview

Package memstream is an expandable ReadWriteSeeker for Golang that works with an internally managed byte buffer. Operation is usage is intended to be seamless and smooth.

In situations where the maximum read/write sizes are known, a fixed []byte/byte buffer will likely offer better performance.

Index

Constants

View Source
const DefaultCapacity = 512

DefaultCapacity is the size in bytes of a new MemoryStream's backing buffer

Variables

This section is empty.

Functions

This section is empty.

Types

type MemoryStream

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

MemoryStream is a memory-based, automatically resizing stream that can easily fill the role of any file-based IO.

func New

func New() *MemoryStream

New creates a new MemoryStream instance

func NewCapacity

func NewCapacity(cap int) *MemoryStream

NewCapacity starts the returned MemoryStream with the given capacity

func (*MemoryStream) Bytes

func (m *MemoryStream) Bytes() []byte

Bytes returns a copy of ALL valid bytes in the stream, regardless of the current position.

func (*MemoryStream) Read

func (m *MemoryStream) Read(p []byte) (n int, err error)

Read puts up to len(p) bytes into p. Will return the number of bytes read.

func (*MemoryStream) Rewind

func (m *MemoryStream) Rewind() (int64, error)

Rewind returns the stream to the beginning

func (*MemoryStream) Seek

func (m *MemoryStream) Seek(offset int64, whence int) (int64, error)

Seek sets the offset for the next Read or Write 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.

Seeking to a negative offset is an error. Seeking to any positive offset is legal. If the location is beyond the end of the current length, the position will be placed at length.

func (*MemoryStream) Write

func (m *MemoryStream) Write(p []byte) (n int, err error)

Write writes the given bytes into the memory stream. If needed, the underlying buffer will be expanded to fit the new bytes.

Jump to

Keyboard shortcuts

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