stringwriter.go 551 B

12345678910111213141516171819202122232425262728293031323334353637
  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. "io"
  7. )
  8. const lowerHex = "0123456789abcdef"
  9. type StringWriter struct {
  10. io.Writer
  11. c int
  12. }
  13. func (w *StringWriter) Write(p []byte) (n int, err error) {
  14. if len(p) == 0 {
  15. return
  16. }
  17. buf := []byte(`\x00`)
  18. var b byte
  19. for n, b = range p {
  20. buf[2] = lowerHex[b/16]
  21. buf[3] = lowerHex[b%16]
  22. w.Writer.Write(buf)
  23. w.c++
  24. }
  25. n++
  26. return
  27. }