bindata/gowriter.go

36 lines
521 B
Go
Raw Normal View History

// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// license. Its contents can be found at:
// http://creativecommons.org/publicdomain/zero/1.0/
package main
import (
"fmt"
"io"
)
var line = []byte("\"+\n\"")
2012-06-07 21:34:34 +00:00
type GoWriter struct {
io.Writer
c int
}
2011-12-07 12:49:06 +00:00
func (w *GoWriter) Write(p []byte) (n int, err error) {
if len(p) == 0 {
return
}
for n = range p {
if w.c%16 == 0 {
w.Writer.Write(line)
2011-12-07 12:49:06 +00:00
w.c = 0
}
fmt.Fprintf(w.Writer, "\\x%02x", p[n])
2011-12-07 12:49:06 +00:00
w.c++
}
return
}