From c8b99b97dffbc7c96b3911f6301f0ec69399cea2 Mon Sep 17 00:00:00 2001 From: Carlos Tadeu Panato Junior Date: Thu, 14 Jun 2018 19:27:21 +0200 Subject: Update html2text lib to use the original repo (#8900) --- vendor/github.com/ssor/bom/bom.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 vendor/github.com/ssor/bom/bom.go (limited to 'vendor/github.com/ssor/bom/bom.go') diff --git a/vendor/github.com/ssor/bom/bom.go b/vendor/github.com/ssor/bom/bom.go new file mode 100644 index 000000000..907ea98d6 --- /dev/null +++ b/vendor/github.com/ssor/bom/bom.go @@ -0,0 +1,34 @@ +package bom + +import ( + "bytes" + "io" + "io/ioutil" +) + +const ( + bom0 = 0xef + bom1 = 0xbb + bom2 = 0xbf +) + +// CleanBom returns b with the 3 byte BOM stripped off the front if it is present. +// If the BOM is not present, then b is returned. +func CleanBom(b []byte) []byte { + if len(b) >= 3 && + b[0] == bom0 && + b[1] == bom1 && + b[2] == bom2 { + return b[3:] + } + return b +} + +// NewReaderWithoutBom returns an io.Reader that will skip over initial UTF-8 byte order marks. +func NewReaderWithoutBom(r io.Reader) (io.Reader, error) { + bs, err := ioutil.ReadAll(r) + if err != nil { + return nil, err + } + return bytes.NewReader(CleanBom(bs)), nil +} -- cgit v1.2.3-1-g7c22