bytewriter.go 668 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
  2. // license. Its contents can be found at:
  3. // http://creativecommons.org/publicdomain/zero/1.0/
  4. package bindata
  5. import (
  6. "fmt"
  7. "io"
  8. )
  9. var (
  10. newline = []byte{'\n'}
  11. dataindent = []byte{'\t', '\t'}
  12. space = []byte{' '}
  13. )
  14. type ByteWriter struct {
  15. io.Writer
  16. c int
  17. }
  18. func (w *ByteWriter) Write(p []byte) (n int, err error) {
  19. if len(p) == 0 {
  20. return
  21. }
  22. for n = range p {
  23. if w.c%12 == 0 {
  24. w.Writer.Write(newline)
  25. w.Writer.Write(dataindent)
  26. w.c = 0
  27. } else {
  28. w.Writer.Write(space)
  29. }
  30. fmt.Fprintf(w.Writer, "0x%02x,", p[n])
  31. w.c++
  32. }
  33. n++
  34. return
  35. }