encoding

package
v0.0.0-...-aadb80c Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package encoding provides a k6 JS module that implements the TextEncoder and TextDecoder interfaces.

Index

Constants

View Source
const (
	// ArrayBufferConstructor is the name of the ArrayBufferConstructor constructor
	ArrayBufferConstructor JSType = "ArrayBuffer"

	// DataViewConstructor is the name of the DataView constructor
	DataViewConstructor = "DataView"

	// Int8ArrayConstructor is the name of the Int8ArrayConstructor constructor
	Int8ArrayConstructor = "Int8Array"

	// Uint8ArrayConstructor is the name of the Uint8ArrayConstructor constructor
	Uint8ArrayConstructor = "Uint8Array"

	// Uint8ClampedArrayConstructor is the name of the Uint8ClampedArrayConstructor constructor
	Uint8ClampedArrayConstructor = "Uint8ClampedArray"

	// Int16ArrayConstructor is the name of the Int16ArrayConstructor constructor
	Int16ArrayConstructor = "Int16Array"

	// Uint16ArrayConstructor is the name of the Uint16ArrayConstructor constructor
	Uint16ArrayConstructor = "Uint16Array"

	// Int32ArrayConstructor is the name of the Int32ArrayConstructor constructor
	Int32ArrayConstructor = "Int32Array"

	// Uint32ArrayConstructor is the name of the Uint32ArrayConstructor constructor
	Uint32ArrayConstructor = "Uint32Array"

	// Float32ArrayConstructor is the name of the Float32ArrayConstructor constructor
	Float32ArrayConstructor = "Float32Array"

	// Float64ArrayConstructor is the name of the Float64ArrayConstructor constructor
	Float64ArrayConstructor = "Float64Array"

	// BigInt64ArrayConstructor is the name of the BigInt64ArrayConstructor constructor
	BigInt64ArrayConstructor = "BigInt64Array"

	// BigUint64ArrayConstructor is the name of the BigUint64ArrayConstructor constructor
	BigUint64ArrayConstructor = "BigUint64Array"
)
View Source
const (
	// UTF8EncodingFormat is the encoding format for utf-8
	UTF8EncodingFormat = "utf-8"

	// UTF16LEEncodingFormat is the encoding format for utf-16le
	UTF16LEEncodingFormat = "utf-16le"

	// UTF16BEEncodingFormat is the encoding format for utf-16be
	UTF16BEEncodingFormat = "utf-16be"
)

Variables

This section is empty.

Functions

func IsInstanceOf

func IsInstanceOf(rt *goja.Runtime, v goja.Value, instanceOf ...JSType) bool

IsInstanceOf returns true if the given value is an instance of the given constructor This uses the technique described in https://github.com/dop251/goja/issues/379#issuecomment-1164441879

func IsTypedArray

func IsTypedArray(rt *goja.Runtime, v goja.Value) bool

IsTypedArray returns true if the given value is an instance of a Typed Array

Types

type EncodingName

type EncodingName = string

EncodingName is a type alias for the name of an encoding.

type Error

type Error struct {
	// Name contains one of the strings associated with an error name.
	Name ErrorName `json:"name"`

	// Message represents message or description associated with the given error name.
	Message string `json:"message"`
}

Error represents an encoding error.

func NewError

func NewError(name, message string) *Error

NewError returns a new Error instance.

func (*Error) Error

func (e *Error) Error() string

Error implements the `error` interface.

type ErrorName

type ErrorName = string

ErrorName is a type alias for the name of an encoding error.

Note that it is a type alias, and not a binding, so that it is not interpreted as an object by goja.

const (
	// RangeError is thrown if the value of label is unknown, or
	// is one of the values leading to a 'replacement' decoding
	// algorithm ("iso-2022-cn" or "iso-2022-cn-ext").
	RangeError ErrorName = "RangeError"

	// TypeError is thrown if the value if the Decoder fatal option
	// is set and the input data cannot be decoded.
	TypeError ErrorName = "TypeError"
)

type JSType

type JSType string

JSType is a string representing a JavaScript type

type ModuleInstance

type ModuleInstance struct {
	*TextDecoder
	*TextEncoder
	// contains filtered or unexported fields
}

ModuleInstance represents an instance of the JS module.

func (*ModuleInstance) Exports

func (mi *ModuleInstance) Exports() modules.Exports

Exports implements the modules.Instance interface and returns the exports of the JS module.

func (*ModuleInstance) NewTextDecoder

func (mi *ModuleInstance) NewTextDecoder(call goja.ConstructorCall) *goja.Object

NewTextDecoder is the JS constructor for the TextDecoder object.

func (*ModuleInstance) NewTextEncoder

func (mi *ModuleInstance) NewTextEncoder(_ goja.ConstructorCall) *goja.Object

NewTextEncoder is the JS constructor for the TextEncoder object.

type RootModule

type RootModule struct{}

RootModule is the global module instance that will create Client instances for each VU.

func New

func New() *RootModule

New returns a pointer to a new RootModule instance

func (*RootModule) NewModuleInstance

func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance

NewModuleInstance implements the modules.Module interface and returns a new instance for each VU.

type TextDecoder

type TextDecoder struct {
	// Encoding holds the name of the decoder which is a string describing
	// the method the `TextDecoder` will use.
	Encoding EncodingName

	// Fatal holds a boolean indicating whether the error mode is fatal.
	Fatal bool

	// IgnoreBOM holds a boolean indicating whether the byte order mark is ignored.
	IgnoreBOM bool
	// contains filtered or unexported fields
}

TextDecoder represents a decoder for a specific text encoding, such as UTF-8, UTF-16, ISO-8859-2, etc.

A decoder takes a stream of bytes as input and emits a stream of code points.

func NewTextDecoder

func NewTextDecoder(rt *goja.Runtime, label string, options textDecoderOptions) (*TextDecoder, error)

NewTextDecoder returns a new TextDecoder object instance that will generate a string from a byte stream with a specific encoding.

func (*TextDecoder) Decode

func (td *TextDecoder) Decode(buffer []byte, options decodeOptions) (string, error)

Decode takes a byte stream as input and returns a string.

type TextEncoder

type TextEncoder struct {
	// Encoding always holds the `utf-8` value.
	// FIXME: this should be TextEncoder.prototype.encoding instead
	Encoding EncodingName
	// contains filtered or unexported fields
}

TextEncoder represents an encoder that will generate a byte stream with UTF-8 encoding.

func NewTextEncoder

func NewTextEncoder() *TextEncoder

NewTextEncoder returns a new TextEncoder object instance that will generate a byte stream with UTF-8 encoding.

func (*TextEncoder) Encode

func (te *TextEncoder) Encode(text string) ([]byte, error)

Encode takes a string as input and returns an encoded byte stream.

Jump to

Keyboard shortcuts

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