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 ¶
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.
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 ¶
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 ¶
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) Fail ¶
Fail breaks the body off: reads return err once they took what was written, and writes fail.
func (*Pipe) Read ¶
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.