trackedoffset

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package trackedoffset provides readers and writers that will keep track of the current offset as data is being read or written to and from.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

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

File wraps an os.File and keeps track of the current offset without requiring constant calls to Seek which involves syscall Lseek to be made. Reading and Writing is buffered by using the bufio package. Implements the following interfaces: io.Reader, io.Writer, io.Seeker, io.ByteReader.

func Create

func Create(path string) (*File, error)

Create a file for reading and writing. Wraps os.Create.

func NewFile

func NewFile(of *os.File) (*File, error)

Create a new File.

func Open

func Open(path string) (*File, error)

Open a file for reading. Wraps os.Open.

func OpenFile

func OpenFile(path string, flag int, perm os.FileMode) (*File, error)

Wraps os.OpenFile to allow for more options.

func (*File) Close

func (f *File) Close() error

Close the file and release resources.

func (*File) Discard added in v0.2.0

func (f *File) Discard(n int) (int, error)

Skips the next n bytes, returning the number of bytes discarded.

func (*File) File added in v0.2.0

func (f *File) File() *os.File

Access the underlying os.File.

func (*File) Flush

func (f *File) Flush() error

Ensure any unwritten data in the write buffer is written to the actual file.

func (*File) Name

func (f *File) Name() string

Path of the file.

func (*File) Offset

func (f *File) Offset() uint64

Return the current offset in bytes.

func (*File) Peek added in v0.2.0

func (f *File) Peek(n int) ([]byte, error)

Peek returns the next n bytes without advancing the offset or the reader. See bufio.Reader.Peek.

func (*File) Read

func (f *File) Read(p []byte) (int, error)

io.Reader.

func (*File) ReadByte

func (f *File) ReadByte() (byte, error)

io.ByteReader.

func (*File) ReadRune added in v0.2.0

func (f *File) ReadRune() (rune, int, error)

Reads a single UTF-8 encoded Unicode character and returns the rune and its size in bytes. If the encoded rune is invalid, it consumes one byte and returns unicode.ReplacementChar (U+FFFD) with a size of 1.

func (*File) Reader added in v0.2.0

func (f *File) Reader() *bufio.Reader

Access the underlying bufio.Reader.

func (*File) ResetReadBuffer

func (f *File) ResetReadBuffer()

Discard any buffered data that has not yet been read. Ensure you call this if you have changed the current offset using Seek.

func (*File) ResetWriteBuffer

func (f *File) ResetWriteBuffer()

Discard any buffered data that has not yet been written. Ensure you call this if you have changed the current offset using Seek.

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

io.Seeker. It is recommended that you ResetReadBuffer or ResetWriteBuffer.

func (*File) SetOffset added in v0.2.0

func (f *File) SetOffset(newOffset uint64)

Set the current offset in bytes.

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

Return information describing the file.

func (*File) Sync

func (f *File) Sync() error

Sync commits the current contents of the file to stable storage.

func (*File) SyncOffset

func (f *File) SyncOffset() error

Ensure the File's offset and the underlying os.File's actual offsets are the same. This will make a call to file.Seek.

func (*File) UnreadByte added in v0.2.0

func (f *File) UnreadByte() error

Unreads the last byte. Only the most recently read byte can be unread. See [bufio.Reader. UnreadByte].

func (*File) Write

func (f *File) Write(p []byte) (int, error)

io.Writer.

func (*File) WriteByte

func (f *File) WriteByte(c byte) error

io.ByteWriter.

func (*File) WriteRune added in v0.2.0

func (f *File) WriteRune(r rune) (int, error)

Writes a single Unicode code point, returning the number of bytes written and any error.

func (*File) Writer added in v0.2.0

func (f *File) Writer() *bufio.Writer

Access the underlying bufio.Writer.

type Reader

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

Reader keeps track of the offset within an io.Reader source.

func NewReader

func NewReader(rd io.Reader, baseOffset uint64) *Reader

Create a new Reader that will keep track of the offset within the source io.Reader. baseOffset is the known starting offset.

func (*Reader) Offset

func (r *Reader) Offset() uint64

Return the current offset in bytes.

func (*Reader) Read

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

Reader implementation.

func (*Reader) ResetOffset

func (r *Reader) ResetOffset(offset uint64)

Set the known offset in bytes.

type Writer

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

Writer keeps track of the offset within an io.Writer source.

func NewWriter

func NewWriter(wd io.Writer, baseOffset uint64) *Writer

Create a new Writer that will keep track of the offset within the source io.Writer.

func (*Writer) Offset

func (w *Writer) Offset() uint64

Return the current offset in bytes.

func (*Writer) ResetOffset

func (w *Writer) ResetOffset(offset uint64)

Set the known offset in bytes.

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Writer implementation.

Jump to

Keyboard shortcuts

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