ioutil

package
v1.4.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package ioutil contains various I/O helpers.

Segmented files

SegmentedReader and SegmentedWriter define a file format that allows a single file to be partitioned into multiple independent sections. Each section has a header that specifies the size and type of the section and the offset of the next section. Thus the sections form a kind of linked list within the file.

Each section consists of a 64 byte header followed by data. The data can have any length, but the space on disk (in the file) will be padded to the nearest multiple of 64 to ensure the headers are aligned on 64-byte boundaries. When a section is opened for writing, if it is not the first section, its offset is recorded in the previous section's header. When a section writer is closed, the length of data written is recorded in the section's header and the file's offset is advanced to the next 64-byte boundary.

Section headers are structured as follows:

  • Type - 2 bytes
  • (reserved) - 6 bytes
  • Size - 8 bytes
  • Next section offset - 8 bytes
  • (reserved) - 40 bytes

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendToSegmented added in v1.4.0

func AppendToSegmented[V enumGet, U enumSet[V]](f io.ReadWriteSeeker) (*SegmentedWriter[V, U], []*Segment[V, U], error)

func NewSectionReader

func NewSectionReader(rd SectionReader, start, end int64) (*io.SectionReader, error)

Types

type Buffer

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

Buffer is an io.ReadWriteSeeker and io.ReaderAt backed by a byte array.

func NewBuffer

func NewBuffer(b []byte) *Buffer

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

func (*Buffer) Read

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

func (*Buffer) ReadAt

func (b *Buffer) ReadAt(v []byte, off int64) (int, error)

func (*Buffer) Seek

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

func (*Buffer) Write

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

type Discard added in v1.2.10

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

Discard is an io.WriteSeeker that discards all data written to it.

func (*Discard) Seek added in v1.2.10

func (d *Discard) Seek(offset int64, whence int) (int64, error)

func (*Discard) Write added in v1.2.10

func (d *Discard) Write(p []byte) (n int, err error)

type SectionReader

type SectionReader interface {
	io.Reader
	io.ReaderAt
	io.Seeker
}

type SectionWriter

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

func NewSectionWriter

func NewSectionWriter(wr io.WriteSeeker, start, end int64) (*SectionWriter, error)

func (*SectionWriter) Seek

func (s *SectionWriter) Seek(offset int64, whence int) (int64, error)

func (*SectionWriter) Write

func (s *SectionWriter) Write(p []byte) (n int, err error)

type Segment

type Segment[V enumGet, U enumSet[V]] struct {
	// contains filtered or unexported fields
}

Segment is a segment of a file.

func (*Segment[V, U]) Offset

func (s *Segment[V, U]) Offset() int64

Offset returns the segment's offset.

func (*Segment[V, U]) Open

func (s *Segment[V, U]) Open() (SectionReader, error)

Open opens the segment for reading.

func (*Segment[V, U]) Size

func (s *Segment[V, U]) Size() int64

Size returns the segment's size.

func (*Segment[V, U]) Type

func (s *Segment[V, U]) Type() V

Type returns the segment's type.

type SegmentWriter

type SegmentWriter[V enumGet, U enumSet[V]] struct {
	// contains filtered or unexported fields
}

A SegmentWriter writes a section of a segmented file.

func (*SegmentWriter[V, U]) Close

func (w *SegmentWriter[V, U]) Close() error

Close closes the segment and finalizes its header.

func (*SegmentWriter[V, U]) Seek

func (w *SegmentWriter[V, U]) Seek(offset int64, whence int) (int64, error)

Seek seeks to an offset.

func (*SegmentWriter[V, U]) Type

func (s *SegmentWriter[V, U]) Type() V

Type returns the segment's type.

func (*SegmentWriter[V, U]) Write

func (w *SegmentWriter[V, U]) Write(p []byte) (n int, err error)

Write writes bytes.

type SegmentedReader

type SegmentedReader[V enumGet, U enumSet[V]] struct {
	// contains filtered or unexported fields
}

SegmentedReader reads a segmented file.

func NewSegmentedReader

func NewSegmentedReader[V enumGet, U enumSet[V]](file SectionReader) *SegmentedReader[V, U]

NewSegmentedReader returns a new segmented reader for the file.

func (*SegmentedReader[V, U]) Next

func (r *SegmentedReader[V, U]) Next() (*Segment[V, U], error)

Next finds the segment.

type SegmentedWriter

type SegmentedWriter[V enumGet, U enumSet[V]] struct {
	// contains filtered or unexported fields
}

SegmentedWriter writes a segmented file.

func NewSegmentedWriter

func NewSegmentedWriter[V enumGet, U enumSet[V]](w io.WriteSeeker) *SegmentedWriter[V, U]

NewSegmentedWriter returns a new segmented writer.

func (*SegmentedWriter[V, U]) Open

func (w *SegmentedWriter[V, U]) Open(typ V) (*SegmentWriter[V, U], error)

Open opens a segment.

Jump to

Keyboard shortcuts

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