MCPcopy Index your code
hub / github.com/dimchansky/utfbom

github.com/dimchansky/utfbom @v1.1.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.1.1 ↗ · + Follow
28 symbols 61 edges 2 files 6 documented · 21% 78 cross-repo links updated 2y agov1.1.1 · 2020-11-06★ 1365 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

utfbom Godoc License Build Status Go Report Card Coverage Status

The package utfbom implements the detection of the BOM (Unicode Byte Order Mark) and removing as necessary. It can also return the encoding detected by the BOM.

Installation

go get -u github.com/dimchansky/utfbom

Example

package main

import (
    "bytes"
    "fmt"
    "io/ioutil"

    "github.com/dimchansky/utfbom"
)

func main() {
    trySkip([]byte("\xEF\xBB\xBFhello"))
    trySkip([]byte("hello"))
}

func trySkip(byteData []byte) {
    fmt.Println("Input:", byteData)

    // just skip BOM
    output, err := ioutil.ReadAll(utfbom.SkipOnly(bytes.NewReader(byteData)))
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println("ReadAll with BOM skipping", output)

    // skip BOM and detect encoding
    sr, enc := utfbom.Skip(bytes.NewReader(byteData))
    fmt.Printf("Detected encoding: %s\n", enc)
    output, err = ioutil.ReadAll(sr)
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println("ReadAll with BOM detection and skipping", output)
    fmt.Println()
}

Output:

$ go run main.go
Input: [239 187 191 104 101 108 108 111]
ReadAll with BOM skipping [104 101 108 108 111]
Detected encoding: UTF8
ReadAll with BOM detection and skipping [104 101 108 108 111]

Input: [104 101 108 108 111]
ReadAll with BOM skipping [104 101 108 108 111]
Detected encoding: Unknown
ReadAll with BOM detection and skipping [104 101 108 108 111]

Core symbols most depended-on inside this repo

nilIfEmpty
called by 8
utfbom.go
Skip
called by 5
utfbom.go
SkipOnly
called by 3
utfbom.go
String
called by 2
utfbom.go
Read
called by 1
utfbom.go
readErr
called by 1
utfbom.go
detectUtf
called by 1
utfbom.go
readBOM
called by 1
utfbom.go

Shape

Function 17
Method 6
Struct 4
TypeAlias 1

Languages

Go100%

Modules by API surface

utfbom.go15 symbols
utfbom_test.go13 symbols

For agents

$ claude mcp add utfbom \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page