stream

package
v1.16.3 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownScheme is returned when an unknown scheme is encountered in a URL.
	ErrUnknownScheme = errors.New("unknown scheme")

	// ErrInvalidSource is returned when an invalid source is encountered.
	ErrInvalidSource = errors.New("invalid source")
)

Functions

func Open

func Open(uri string) (io.ReadCloser, error)

Open opens a resource identified by the given URI. It supports different schemes by utilizing registered open functions. If the URI has no scheme, it is treated as a file path.

func ReadSource added in v1.16.3

func ReadSource(src any) ([]byte, error)

ReadSource converts src to a []byte if possible; otherwise it returns an error. Supported types for src are:

  • string (as content, NOT as filename)
  • []byte (as content)
  • *bytes.Buffer (as content)
  • io.Reader (as content)

func ReadSourceFromURI added in v1.16.3

func ReadSourceFromURI(uri string, src any) ([]byte, error)

ReadSourceFromURI reads the source from the given URI. If src != nil, it reads from src; otherwise, it opens the URI and reads from it.

func ReadSourceLocal added in v1.16.3

func ReadSourceLocal(filename string, src any) ([]byte, error)

If src != nil, ReadSourceLocal converts src to a []byte if possible; otherwise it returns an error. If src == nil, ReadSourceLocal returns the result of reading the file specified by filename.

func Register

func Register(scheme string, open OpenFunc)

Register registers a scheme with an open function.

Types

type OpenFunc

type OpenFunc = func(url string) (io.ReadCloser, error)

OpenFunc defines the function type for opening a resource by URL.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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