forked from shuLhan/go-bindata
-
Notifications
You must be signed in to change notification settings - Fork 2
/
bytewriter.go
61 lines (50 loc) · 905 Bytes
/
bytewriter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// 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 bindata
import (
"fmt"
"io"
)
var (
newline = []byte{'\n'}
dataindent = []byte{'\t', '\t'}
space = []byte{' '}
)
//
// ByteWriter define a writer to write content of file.
//
type ByteWriter struct {
io.Writer
c int
}
func (w *ByteWriter) Write(p []byte) (n int, err error) {
if len(p) == 0 {
return
}
for n = range p {
if w.c%12 == 0 {
_, err = w.Writer.Write(newline)
if err != nil {
return
}
_, err = w.Writer.Write(dataindent)
if err != nil {
return
}
w.c = 0
} else {
_, err = w.Writer.Write(space)
if err != nil {
return
}
}
_, err = fmt.Fprintf(w.Writer, "0x%02x,", p[n])
if err != nil {
return
}
w.c++
}
n++
return
}