chunked

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2025 License: MIT Imports: 14 Imported by: 2

Documentation

Overview

Package chunked provides a mechanism to read and write chunked data files.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound indicates that the specified content is not available.

Functions

This section is empty.

Types

type Asset

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

func NewAsset

func NewAsset(storage Storage, path string) *Asset

func (*Asset) Path

func (a *Asset) Path() string

func (*Asset) Read

func (a *Asset) Read(target any) error

func (*Asset) Write

func (a *Asset) Write(source any) error

type Chunk

type Chunk interface {
	ChunkID() string
	Encode(out *gblob.PackedEncoder) error
	Decode(in *gblob.PackedDecoder) error
}

type ChunkConsumer

type ChunkConsumer interface {
	AddChunk(chunk Chunk)
}

type ChunkHolder

type ChunkHolder struct {
	Items []Chunk
}

func (*ChunkHolder) AddChunk

func (h *ChunkHolder) AddChunk(chunk Chunk)

func (ChunkHolder) Chunks

func (h ChunkHolder) Chunks() []Chunk

type ChunkList

type ChunkList []Chunk

func (ChunkList) Chunks

func (l ChunkList) Chunks() []Chunk

type ChunkProvider

type ChunkProvider interface {
	Chunks() []Chunk
}

type RawChunk

type RawChunk struct {
	ID   string
	Data RawData
}

func (RawChunk) ChunkID

func (c RawChunk) ChunkID() string

func (RawChunk) Decode

func (c RawChunk) Decode(in *gblob.PackedDecoder) error

func (RawChunk) Encode

func (c RawChunk) Encode(out *gblob.PackedEncoder) error

type RawData

type RawData []byte

func (RawData) DecodePacked

func (c RawData) DecodePacked(reader gblob.TypedReader) error

func (RawData) EncodePacked

func (c RawData) EncodePacked(writer gblob.TypedWriter) error

type Storage

type Storage interface {

	// List returns all available assets.
	List() ([]string, error)

	// Open opens a reader for the data of the specified asset.
	Open(path string) (io.ReadCloser, error)

	// Create opens a writer for the data of the specified asset.
	Create(path string) (io.WriteCloser, error)

	// Delete removes the specified asset.
	Delete(path string) error
}

Storage represents a storage interface for assets.

func NewFileStorage

func NewFileStorage(baseDir string) (Storage, error)

NewFileStorage creates a new storage that uses the file system.

func NewMemoryStorage

func NewMemoryStorage() Storage

NewMemoryStorage creates a new storage that uses memory.

func NewWebStorage

func NewWebStorage(baseURL string) (Storage, error)

NewWebStorage creates a new storage that uses HTTP requests.

type ValueChunk

type ValueChunk[T any] struct {
	ID    string
	Value T
}

func FromValue

func FromValue[T any](id string, value T) *ValueChunk[T]

func (*ValueChunk[T]) ChunkID

func (c *ValueChunk[T]) ChunkID() string

func (*ValueChunk[T]) Decode

func (c *ValueChunk[T]) Decode(in *gblob.PackedDecoder) error

func (*ValueChunk[T]) Encode

func (c *ValueChunk[T]) Encode(out *gblob.PackedEncoder) error

Jump to

Keyboard shortcuts

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