Skip to content

Instantly share code, notes, and snippets.

@owulveryck
Created January 2, 2019 15:37
Show Gist options
  • Save owulveryck/ed8938f1ea7bac32af91c1357d5a040d to your computer and use it in GitHub Desktop.
Save owulveryck/ed8938f1ea7bac32af91c1357d5a040d to your computer and use it in GitHub Desktop.
read file from string
func main() {
b, err := ioutil.ReadFile("model.onnx")
if err != nil {
panic(err)
}
/*
var qb bytes.Buffer
fmt.Fprint(&qb, `data := "`)
print(&qb, b)
fmt.Fprint(&qb, `"`)
if err = ioutil.WriteFile("olwu.go", qb.Bytes(), 0644); err != nil {
return
}
*/
if string(b) == data {
fmt.Println("ok")
}
}
func print(dest *bytes.Buffer, data []byte) {
for _, b := range data {
if b == '\n' {
dest.WriteString(`\n`)
continue
}
if b == '\\' {
dest.WriteString(`\\`)
continue
}
if b == '"' {
dest.WriteString(`\"`)
continue
}
if (b >= 32 && b <= 126) || b == '\t' {
dest.WriteByte(b)
continue
}
fmt.Fprintf(dest, "\\x%02x", b)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment