Created
January 2, 2019 15:37
-
-
Save owulveryck/ed8938f1ea7bac32af91c1357d5a040d to your computer and use it in GitHub Desktop.
read file from string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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