docker testing
This commit is contained in:
36
cmd/slicewriter/slicewriter.go
Normal file
36
cmd/slicewriter/slicewriter.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package slicewriter
|
||||
|
||||
import "io"
|
||||
|
||||
type SliceWriter struct {
|
||||
off int
|
||||
buf []byte
|
||||
}
|
||||
|
||||
func (w *SliceWriter) Write(p []byte) (int, error) {
|
||||
if len(p)+w.off <= len(w.buf) {
|
||||
copy(w.buf[w.off:], p)
|
||||
w.off += len(p)
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
space := len(w.buf) - w.off
|
||||
copy(w.buf[:w.off], p[:space])
|
||||
w.off += space
|
||||
return space, io.ErrShortWrite
|
||||
}
|
||||
|
||||
func (w *SliceWriter) Reset() {
|
||||
w.off = 0
|
||||
}
|
||||
|
||||
func (w *SliceWriter) Bytes() []byte {
|
||||
return w.buf[:w.off]
|
||||
}
|
||||
|
||||
func NewSliceWriter(b []byte) *SliceWriter {
|
||||
return &SliceWriter{
|
||||
off: 0,
|
||||
buf: b,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user