diff options
author | Michael Muré <batolettre@gmail.com> | 2018-07-16 23:20:23 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-07-16 23:23:43 +0200 |
commit | 1d678dfdfa026968dbb19795c9bed16385603b21 (patch) | |
tree | cac862609d0103ee30da39cd0054b11884248e9d /vendor/github.com/shurcooL/vfsgen/stringwriter.go | |
parent | 131a862d313f12808d63e832126317a27226940b (diff) | |
download | git-bug-1d678dfdfa026968dbb19795c9bed16385603b21.tar.gz |
vendor dependencies with dep
Diffstat (limited to 'vendor/github.com/shurcooL/vfsgen/stringwriter.go')
-rw-r--r-- | vendor/github.com/shurcooL/vfsgen/stringwriter.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/vendor/github.com/shurcooL/vfsgen/stringwriter.go b/vendor/github.com/shurcooL/vfsgen/stringwriter.go new file mode 100644 index 00000000..a781efdc --- /dev/null +++ b/vendor/github.com/shurcooL/vfsgen/stringwriter.go @@ -0,0 +1,27 @@ +package vfsgen + +import ( + "io" +) + +// stringWriter writes given bytes to underlying io.Writer as a Go interpreted string literal value, +// not including double quotes. It tracks the total number of bytes written. +type stringWriter struct { + io.Writer + N int64 // Total bytes written. +} + +func (sw *stringWriter) Write(p []byte) (n int, err error) { + const hex = "0123456789abcdef" + buf := []byte{'\\', 'x', 0, 0} + for _, b := range p { + buf[2], buf[3] = hex[b/16], hex[b%16] + _, err = sw.Writer.Write(buf) + if err != nil { + return n, err + } + n++ + sw.N++ + } + return n, nil +} |