Goè¨èªã§utf8ã®bomãåé¤ãã
é¢é£ : Python2ã§utf8ã®bomãåé¤ãã - brainstorm
TrimPrefixã使ãã
package main import ( "bytes" "flag" "fmt" "io/ioutil" "os" ) var UTF8_BOM = []byte{239, 187, 191} func hasBOM(in []byte) bool { return bytes.HasPrefix(in, UTF8_BOM) } func stripBOM(in []byte) []byte { return bytes.TrimPrefix(in, UTF8_BOM) } func main() { flag.Parse() defer func() { if err := recover(); err != nil { fmt.Fprintln(os.Stderr, "error:", err) os.Exit(1) } }() content, err := ioutil.ReadFile(flag.Arg(0)) if err != nil { panic(err) } err = ioutil.WriteFile(flag.Arg(1), stripBOM(content), 0644) if err != nil { panic(err) } }