...

Package utfbom

import "github.com/dimchansky/utfbom"
Overview
Index

Overview ▾

Package utfbom implements the detection of the BOM (Unicode Byte Order Mark) and removing as necessary. It wraps an io.Reader object, creating another object (Reader) that also implements the io.Reader interface but provides automatic BOM checking and removing as necessary.

func Skip

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

Skip 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 SkipOnly function.

type Encoding

Encoding is type alias for detected UTF encoding.

type Encoding int

Constants to identify detected UTF encodings.

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

    // UTF8, BOM bytes: EF BB BF
    UTF8

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

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

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

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

func (Encoding) String

func (e Encoding) String() string

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

type Reader

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

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

func SkipOnly

func SkipOnly(rd io.Reader) *Reader

SkipOnly creates Reader which automatically detects BOM (Unicode Byte Order Mark) and removes it as necessary.

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.