buffer

package
v0.0.0-...-2435b8f Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package buffer implements a memory buffer with a limited capacity that can overflow into a file on disk.

Example:

var r io.Reader = …
b := buffer.Buffer{Capacity: 10<<20}
defer b.Cleanup()
if _, err := io.Copy(b, r); err != nil {
  log.Fatal(err)
}

var w io.Writer = …
if _, err = b.WriteTo(w); err != nil {
  log.Fatal(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	// The maximum number of bytes that will be buffered in memory before
	// switching to a file.  If ≤ 0, all data will be stored on disk.
	Capacity int

	// The path of the temporary file that will be used to store overflow.  If
	// this field is "", a path is chosen by ioutil.TempFile when required; the
	// caller may read this field to find out the name that was chosen.
	Path string
	// contains filtered or unexported fields
}

A Buffer is a readable and writable buffer that stores data in memory until it exceeds the given capacity in bytes, and thereafter switches to using a temporary file on disk.

func (*Buffer) Cleanup

func (b *Buffer) Cleanup()

Cleanup cleans up the overflow file created by the buffer, if it exists. The caller should either invoke this method, or take responsibility for cleaning up the file directly by reading the Path field.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the number of bytes that are stored in the buffer.

func (*Buffer) Read

func (b *Buffer) Read(data []byte) (int, error)

Read implements io.Reader.

func (*Buffer) Write

func (b *Buffer) Write(data []byte) (int, error)

Write implements io.Writer.

Jump to

Keyboard shortcuts

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