schemestream

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package schemestream holds the parts of streaming custom scheme responses to WebView2 that do not need Windows, so that they are tested everywhere: Pipe, which carries a response's body from the goroutine of its handler to the reads of the webview with bounded memory, and ClampRange, which narrows the open ranges media elements ask for.

Index

Constants

This section is empty.

Variables

View Source
var ErrReleased = errors.New("golet: the webview no longer reads the response")

ErrReleased is what writes return once the reader no longer wants the body: the webview released the stream, or the response was answered another way.

View Source
var ErrTimeout = errors.New("golet: no data to read in time")

ErrTimeout is what Read returns when it waited the time it was given and found nothing to read.

Functions

func ClampRange

func ClampRange(h string, n int64) string

ClampRange narrows a Range header asking for the rest of a resource from a byte on, "bytes=X-", to at most n bytes, "bytes=X-(X+n-1)", and returns other headers as they are. A media element asking an open range takes a shorter answer (206 with its Content-Range) and asks for what follows when it needs it, as it would over HTTP.

Types

type Pipe

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

A Pipe carries a body from one writer, the handler's goroutine, to one reader, the webview. Write waits while the pipe holds limit bytes or more that were not read, so a handler faster than the reader does not pile up memory, and Read waits for as many bytes as it asks for, or the end of the body, so that a short read means the end as with a stream in memory.

func NewPipe

func NewPipe(limit int, onFull func()) *Pipe

NewPipe returns a pipe holding up to about limit bytes. onFull, if not nil, is called once, on the writer's goroutine, the first time a Write waits: then no reader has taken the body yet, or it reads slower than the writer writes.

func (*Pipe) Close

func (p *Pipe) Close()

Close ends the body after what was written.

func (*Pipe) Fail

func (p *Pipe) Fail(err error)

Fail breaks the body off: reads return err once they took what was written, and writes fail.

func (*Pipe) Read

func (p *Pipe) Read(b []byte, timeout time.Duration) (int, error)

Read fills b, waiting until the pipe holds len(b) bytes or the body ended. It returns fewer bytes than len(b) with io.EOF at the end of the body, and the error of Fail, or ErrReleased, once the body broke off and was read up to there. With timeout > 0 it waits at most that long: then it returns what it has, and ErrTimeout if that is nothing.

func (*Pipe) Release

func (p *Pipe) Release()

Release tells the pipe that nothing reads it any more: writes fail from now on, and what they wrote is dropped.

func (*Pipe) Take

func (p *Pipe) Take() []byte

Take returns what was written and not read, and empties the pipe, for a body that ended before anything read it.

func (*Pipe) Write

func (p *Pipe) Write(b []byte) error

Write appends b, after waiting while the pipe is full. It fails once the reader is gone or the body broke off.

Jump to

Keyboard shortcuts

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