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 ¶
- func AppendToSegmented[V enumGet, U enumSet[V]](f io.ReadWriteSeeker) (*SegmentedWriter[V, U], []*Segment[V, U], error)
- func NewSectionReader(rd SectionReader, start, end int64) (*io.SectionReader, error)
- type Buffer
- type Discard
- type SectionReader
- type SectionWriter
- type Segment
- type SegmentWriter
- type SegmentedReader
- type SegmentedWriter
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.
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.
type SectionWriter ¶
type SectionWriter struct {
// contains filtered or unexported fields
}
func NewSectionWriter ¶
func NewSectionWriter(wr io.WriteSeeker, start, end int64) (*SectionWriter, 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]) Open ¶
func (s *Segment[V, U]) Open() (SectionReader, error)
Open opens the segment for reading.
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.
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.