1package vfsgen
2
3import (
4 "io"
5)
6
7// stringWriter writes given bytes to underlying io.Writer as a Go interpreted string literal value,
8// not including double quotes. It tracks the total number of bytes written.
9type stringWriter struct {
10 io.Writer
11 N int64 // Total bytes written.
12}
13
14func (sw *stringWriter) Write(p []byte) (n int, err error) {
15 const hex = "0123456789abcdef"
16 buf := []byte{'\\', 'x', 0, 0}
17 for _, b := range p {
18 buf[2], buf[3] = hex[b/16], hex[b%16]
19 _, err = sw.Writer.Write(buf)
20 if err != nil {
21 return n, err
22 }
23 n++
24 sw.N++
25 }
26 return n, nil
27}