filebuf

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

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

Go to latest
Published: Oct 9, 2024 License: Apache-2.0 Imports: 5 Imported by: 1

README

Reader/write support with buffer in RAM. If more than the declared amount is required, disk memory is used as a buffer. Process files up to hundreds of gigabytes in size without much effort and loading everything into memory.

Example

Look into filebuf_test.go

    //  if you exceed 1024 bytes, store everything else on disk
	buf := filebuf.New(1024, true, false)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTooLarge = errors.New("filebuf: Out of free memory")

Functions

func DefaultBufferSize

func DefaultBufferSize() int

Types

type Buf

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

func New

func New(bufferSize int, useMemory bool, removeAfterClose bool) Buf

func (*Buf) Close

func (b *Buf) Close() (err error)

func (*Buf) Flush

func (b *Buf) Flush() (err error)

func (*Buf) Len

func (b *Buf) Len() int

Len for io.Reader compatibility

func (*Buf) LenInt64

func (b *Buf) LenInt64() int64

func (*Buf) Offset

func (b *Buf) Offset() int64

func (*Buf) Read

func (b *Buf) Read(data []byte) (n int, err error)

func (*Buf) Seek

func (b *Buf) Seek(offset int64, whence int) (int64, error)

func (*Buf) Size

func (b *Buf) Size() (int64, error)

func (*Buf) SwitchToRead

func (b *Buf) SwitchToRead() (err error)

func (*Buf) SwitchToWrite

func (b *Buf) SwitchToWrite() (err error)

func (*Buf) Truncate

func (b *Buf) Truncate(n int64) (err error)

func (*Buf) Write

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

func (*Buf) WriteString

func (b *Buf) WriteString(data string) (int, error)

type ProcessorReadHandler

type ProcessorReadHandler func(r io.Reader) (io.ReadCloser, error)

type ProcessorWriteHandler

type ProcessorWriteHandler func(w io.Writer) (io.Writer, error)

type Reader

type Reader struct {
	*bufio.Reader
	// contains filtered or unexported fields
}

func BufferReader

func BufferReader(r io.Reader, processor ProcessorReadHandler) (*Reader, error)

func (*Reader) Close

func (r *Reader) Close() error

Close the associated files.

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

type Writer

type Writer struct {
	*bufio.Writer
	// contains filtered or unexported fields
}

Writer is returned by Wopen

Jump to

Keyboard shortcuts

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