mem_constrained_buffer

package module
v0.0.0-...-9f8e95f Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: MIT Imports: 5 Imported by: 1

README

mem_constrained_buffer

A simple buffer that is optionally backed by a concrete file on disk when it grows too large.

import (
  "github.com/cardamaro/mem_constrained_buffer"
  "strings"
)

func main() {
  r := strings.NewReader("foobar")
  
  buf := mem_constrained_buffer.NewDefaultMemoryConstrainedBuffer()
  defer buf.Close()  // removes any temp files
  
  if _, err := buf.ReadFrom(r); err != nil {
    panic(err)
  }
  
  fmt.Printf("Read %d bytes", buf.Len())
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultMemorySize int64 = 1 << 17 // 128K
	FilenamePrefix          = "mem-buf-"
	TempDir                 = os.TempDir()
)

Functions

This section is empty.

Types

type MemoryConstrainedBuffer

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

func New

func NewWithSize

func NewWithSize(maxMemory int64, removeOnClose bool) *MemoryConstrainedBuffer

func (*MemoryConstrainedBuffer) Close

func (m *MemoryConstrainedBuffer) Close() error

func (*MemoryConstrainedBuffer) Len

func (m *MemoryConstrainedBuffer) Len() int64

func (*MemoryConstrainedBuffer) Read

func (m *MemoryConstrainedBuffer) Read(p []byte) (int, error)

func (*MemoryConstrainedBuffer) ReadAt

func (m *MemoryConstrainedBuffer) ReadAt(p []byte, off int64) (int, error)

func (*MemoryConstrainedBuffer) ReadFrom

func (m *MemoryConstrainedBuffer) ReadFrom(r io.Reader) (int64, error)

func (*MemoryConstrainedBuffer) Remove

func (m *MemoryConstrainedBuffer) Remove() (err error)

func (*MemoryConstrainedBuffer) Seek

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

func (*MemoryConstrainedBuffer) Write

func (m *MemoryConstrainedBuffer) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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