bom

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package bom nolint

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadSkipBOM

func ReadSkipBOM(rd io.Reader) (*Reader, Encoding)

ReadSkipBOM creates Reader which automatically detects BOM (Unicode Byte Order Mark) and removes it as necessary. It also returns the encoding detected by the BOM. If the detected encoding is not needed, you can call the ReadSkipBOM function.

Types

type Encoding

type Encoding int

Encoding is type alias for detected UTF encoding.

const (
	// Unknown encoding, returned when no BOM was detected
	Unknown Encoding = iota

	// UTF8 , BOM bytes: EF BB BF
	UTF8

	// UTF16BigEndian UTF-16, big-endian, BOM bytes: FE FF
	UTF16BigEndian

	// UTF16LittleEndian UTF-16, little-endian, BOM bytes: FF FE
	UTF16LittleEndian

	// UTF32BigEndian UTF-32, big-endian, BOM bytes: 00 00 FE FF
	UTF32BigEndian

	// UTF32LittleEndian UTF-32, little-endian, BOM bytes: FF FE 00 00
	UTF32LittleEndian
)

Constants to identify detected UTF encodings.

func (Encoding) String

func (e Encoding) String() string

String returns a user-friendly string representation of the encoding. Satisfies fmt.Stringer interface.

type Reader

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

Reader implements automatic BOM (Unicode Byte Order Mark) checking and removing as necessary for an io.Reader object.

func (*Reader) Read

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

Read is an implementation of io.Reader interface. The bytes are taken from the underlying Reader, but it checks for BOMs, removing them as necessary.

type Writer

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

Writer implements automatic BOM (Unicode Byte Order Mark) write

func WriteWithBOM

func WriteWithBOM(wt io.Writer, e Encoding) *Writer

WriteWithBOM creates Writer which automatically write BOM (Unicode Byte Order Mark).

func (*Writer) Available

func (w *Writer) Available() int

Available returns how many bytes are unused in the buffer.

func (*Writer) Buffered

func (w *Writer) Buffered() int

Buffered returns the number of bytes that have been written into the current buffer.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush writes any buffered data to the underlying io.Writer.

func (*Writer) Write

func (w *Writer) Write(p []byte) (nn int, err error)

Write is an implementation of io.Write interface. The bytes are taken from the underlying Write, but it will automatically write for BOMs.

Jump to

Keyboard shortcuts

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