encoding

package
v1.29.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrShortDst means that the destination buffer was too short to
	// receive all of the transformed bytes.
	ErrShortDst = errors.New("transform: short destination buffer")

	// ErrShortSrc means that the source buffer has insufficient data to
	// complete the transformation.
	ErrShortSrc = errors.New("transform: short source buffer")
)

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	transform.Transformer
	// contains filtered or unexported fields
}

A Decoder converts bytes to UTF-8. It implements transform.Transformer.

Transforming source bytes that are not of that encoding will not result in an error per se. Each byte that cannot be transcoded will be represented in the output by the UTF-8 encoding of '\uFFFD', the replacement rune.

func NewDecoder

func NewDecoder(enc string) (*Decoder, error)

NewDecoder returns an x/text Decoder for the specified text encoding. The Decoder converts a character encoding into utf-8 bytes. If a BOM is found it will be converted into an utf-8 BOM, you can use github.com/dimchansky/utfbom to strip the BOM.

The "none" or "" encoding will pass through bytes unchecked. Use the utf-8 encoding if you want invalid bytes replaced using the unicode replacement character.

Detection of utf-16 endianness using the BOM is not currently provided due to the tail input plugins requirement to be able to start at the middle or end of the file.

func (*Decoder) Bytes added in v1.15.2

func (d *Decoder) Bytes(b []byte) ([]byte, error)

Bytes converts the given encoded bytes to UTF-8. It returns the converted bytes or nil, err if any error occurred.

func (*Decoder) Reader added in v1.15.2

func (d *Decoder) Reader(r io.Reader) io.Reader

Reader wraps another Reader to decode its bytes.

The Decoder may not be used for any other operation as long as the returned Reader is in use.

func (*Decoder) String added in v1.15.2

func (d *Decoder) String(s string) (string, error)

String converts the given encoded string to UTF-8. It returns the converted string or "", err if any error occurred.

type Reader added in v1.15.2

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

Reader wraps another io.Reader by transforming the bytes read.

func NewReader added in v1.15.2

func NewReader(r io.Reader, t transform.Transformer) *Reader

NewReader returns a new Reader that wraps r by transforming the bytes read via t. It calls Reset on t.

func (*Reader) Read added in v1.15.2

func (r *Reader) Read(p []byte) (int, error)

Read implements the io.Reader interface.

Jump to

Keyboard shortcuts

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