jsStreams

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: LGPL-3.0 Imports: 6 Imported by: 1

README

jsStreams

Go library to communicate with the JS Stream API by bridging the JS ReadableStream and WritableStream objects to a Go io.ReaderCloser and io.WriterCloser. It also works vice versa, and with pipe readers/writers.

Go Report Card Go Reference

The API is pretty self-explanatory, see the Go Reference badge above for the full documentation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReaderToReadableStream added in v1.2.0

func ReaderToReadableStream(r io.Reader) js.Value

ReaderToReadableStream converts an io.Reader to a JavaScript ReadableStream.

func WriterToWritableStream added in v1.2.0

func WriterToWritableStream(w io.Writer) js.Value

WriterToWritableStream converts an io.Writer to a JavaScript WritableStream.

Types

type ReadableStream

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

ReadableStream implements io.ReadCloser for a JavaScript ReadableStream.

func NewReadableStream

func NewReadableStream(stream js.Value) *ReadableStream

NewReadableStream creates a new ReadableStream from a JavaScript ReadableStream.

func (*ReadableStream) Close

func (r *ReadableStream) Close() (err error)

Close closes the ReadableStream. If the stream is already closed, Close does nothing.

func (*ReadableStream) Read

func (r *ReadableStream) Read(p []byte) (n int, err error)

Read reads up to len(p) bytes into p. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered. This implementation of Read does not use scratch space if n < len(p). If some data is available but not len(p) bytes, Read conventionally returns what is available instead of waiting for more. Note: Read will block until data is available, meaning in a WASM environment, you must use a goroutine to call Read.

type WritableStream

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

WritableStream implements io.WriteCloser for a JavaScript WritableStream.

func NewWritableStream

func NewWritableStream(stream ...js.Value) *WritableStream

NewWritableStream creates a new WritableStream. If a JavaScript WritableStream is provided, it will be used. Otherwise, a new WritableStream will be created.

func (*WritableStream) Close

func (w *WritableStream) Close() (err error)

Close closes the WritableStream. If the stream is already closed, Close does nothing.

func (*WritableStream) Write

func (w *WritableStream) Write(p []byte) (n int, err error)

Write writes len(p) bytes from p to the underlying data stream. It returns the number of bytes written from p (0 <= n <= len(p)) and any error encountered that caused the write to stop early. Write must return a non-nil error if it returns n < len(p). Write must not modify the slice data, even temporarily.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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