io

package
v0.0.0-...-bace2a7 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound         = errors.New("file not found")
	ErrAlreadyExists    = errors.New("file already exists")
	ErrInvalidPath      = errors.New("invalid storage path")
	ErrPermissionDenied = errors.New("permission denied")
)

Standard sentinel storage errors.

Functions

func CleanPath

func CleanPath(p string) string

CleanPath normalizes file paths by stripping the "file://" URI scheme if present.

func JoinPath

func JoinPath(base string, elem ...string) string

JoinPath safely joins path elements while preserving URI schemes (e.g. s3://, mem://, file://).

func ParseS3URI

func ParseS3URI(uri string) (string, string, error)

ParseS3URI extracts bucket and key from an s3:// or s3a:// URI.

Types

type FileInfo

type FileInfo struct {
	Path    string    `json:"path"`
	Size    int64     `json:"size"`
	ModTime time.Time `json:"modTime"`
	IsDir   bool      `json:"isDir"`
}

FileInfo represents metadata for an object or file in storage.

type LocalStorage

type LocalStorage struct{}

LocalStorage implements Storage for the local OS filesystem.

func NewLocalStorage

func NewLocalStorage() *LocalStorage

NewLocalStorage creates a new LocalStorage instance.

func (*LocalStorage) Close

func (s *LocalStorage) Close() error

Close is a no-op for LocalStorage.

func (*LocalStorage) Delete

func (s *LocalStorage) Delete(_ context.Context, path string) error

Delete removes a file or empty directory.

func (*LocalStorage) Exists

func (s *LocalStorage) Exists(_ context.Context, path string) (bool, error)

Exists checks whether a file or directory exists.

func (*LocalStorage) List

func (s *LocalStorage) List(_ context.Context, prefix string) ([]FileInfo, error)

List lists all files under the given prefix or directory path.

func (*LocalStorage) Read

func (s *LocalStorage) Read(_ context.Context, path string) ([]byte, error)

Read reads file contents from the local filesystem.

func (*LocalStorage) Write

func (s *LocalStorage) Write(_ context.Context, path string, data []byte) error

Write writes data to path atomically, creating any parent directories automatically.

type MemoryStorage

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

MemoryStorage implements Storage in-memory for testing, benchmarking, and WASM runtime.

func NewMemoryStorage

func NewMemoryStorage() *MemoryStorage

NewMemoryStorage creates a thread-safe MemoryStorage instance.

func (*MemoryStorage) Close

func (s *MemoryStorage) Close() error

Close is a no-op for MemoryStorage.

func (*MemoryStorage) Delete

func (s *MemoryStorage) Delete(_ context.Context, path string) error

Delete removes the file from memory.

func (*MemoryStorage) Exists

func (s *MemoryStorage) Exists(_ context.Context, path string) (bool, error)

Exists checks if the path exists in memory.

func (*MemoryStorage) List

func (s *MemoryStorage) List(_ context.Context, prefix string) ([]FileInfo, error)

List lists all in-memory files matching the prefix.

func (*MemoryStorage) Read

func (s *MemoryStorage) Read(_ context.Context, path string) ([]byte, error)

Read reads file bytes from the in-memory map.

func (*MemoryStorage) Write

func (s *MemoryStorage) Write(_ context.Context, path string, data []byte) error

Write stores file bytes in the in-memory map.

type S3Options

type S3Options struct {
	Region           string
	Endpoint         string
	UsePathStyle     bool
	CustomHTTPClient aws.HTTPClient
}

S3Options allows configuring custom S3 endpoints, regions, or clients.

type S3Storage

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

S3Storage provides a zero-JVM native AWS S3 storage implementation.

func NewS3Storage

func NewS3Storage(ctx context.Context, optFns ...func(*S3Options)) (*S3Storage, error)

NewS3Storage creates a new S3Storage instance with standard AWS credential discovery.

func NewS3StorageWithClient

func NewS3StorageWithClient(client *s3.Client) *S3Storage

NewS3StorageWithClient initializes S3Storage with an existing S3 client.

func (*S3Storage) Close

func (s *S3Storage) Close() error

Close is a no-op for S3Storage.

func (*S3Storage) Delete

func (s *S3Storage) Delete(ctx context.Context, path string) error

Delete removes an object from S3.

func (*S3Storage) Exists

func (s *S3Storage) Exists(ctx context.Context, path string) (bool, error)

Exists checks if an object exists in S3.

func (*S3Storage) List

func (s *S3Storage) List(ctx context.Context, prefix string) ([]FileInfo, error)

List lists all S3 objects matching the prefix.

func (*S3Storage) Read

func (s *S3Storage) Read(ctx context.Context, path string) ([]byte, error)

Read fetches an object from S3.

func (*S3Storage) Write

func (s *S3Storage) Write(ctx context.Context, path string, data []byte) error

Write uploads data to S3.

type Storage

type Storage interface {
	// Read reads the entire content of the file at the specified path.
	Read(ctx context.Context, path string) ([]byte, error)

	// Write writes the given data to the specified path atomically.
	Write(ctx context.Context, path string, data []byte) error

	// List lists all files and directories matching the prefix.
	List(ctx context.Context, prefix string) ([]FileInfo, error)

	// Exists checks if an object or directory exists at path.
	Exists(ctx context.Context, path string) (bool, error)

	// Delete deletes the file or object at path.
	Delete(ctx context.Context, path string) error

	// Close releases any open network connections or resources.
	Close() error
}

Storage defines the unified storage interface across Local FS, Amazon S3, Google GCS, Azure Blob, and Memory.

func NewStorageForPath

func NewStorageForPath(ctx context.Context, path string) (Storage, error)

NewStorageForPath automatically resolves and instantiates the appropriate Storage implementation for a path URI.

func NewStorageForPathWithOptions

func NewStorageForPathWithOptions(ctx context.Context, path string, optFns ...func(*S3Options)) (Storage, error)

NewStorageForPathWithOptions automatically resolves and instantiates Storage with optional S3 configuration.

Jump to

Keyboard shortcuts

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