summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/philhofer/fwd/writer.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2021-10-16 23:11:32 +0200
committerWim <wim@42.be>2021-10-16 23:23:24 +0200
commit20f6c05ec50739d31f4dbe9fde0d223f2c43f6e8 (patch)
tree230edca06449a8d1755f08aabf45a03e07e6f17c /vendor/github.com/philhofer/fwd/writer.go
parent57fce93af7f64f025cec6f3ed6088163086bc9fe (diff)
downloadmatterbridge-msglm-20f6c05ec50739d31f4dbe9fde0d223f2c43f6e8.tar.gz
matterbridge-msglm-20f6c05ec50739d31f4dbe9fde0d223f2c43f6e8.tar.bz2
matterbridge-msglm-20f6c05ec50739d31f4dbe9fde0d223f2c43f6e8.zip
Update vendor
Diffstat (limited to 'vendor/github.com/philhofer/fwd/writer.go')
-rw-r--r--vendor/github.com/philhofer/fwd/writer.go24
1 files changed, 18 insertions, 6 deletions
diff --git a/vendor/github.com/philhofer/fwd/writer.go b/vendor/github.com/philhofer/fwd/writer.go
index 2dc392a9..4d6ea15b 100644
--- a/vendor/github.com/philhofer/fwd/writer.go
+++ b/vendor/github.com/philhofer/fwd/writer.go
@@ -29,16 +29,28 @@ func NewWriter(w io.Writer) *Writer {
}
}
-// NewWriterSize returns a new writer
-// that writes to 'w' and has a buffer
-// that is 'size' bytes.
-func NewWriterSize(w io.Writer, size int) *Writer {
- if wr, ok := w.(*Writer); ok && cap(wr.buf) >= size {
+// NewWriterSize returns a new writer that
+// writes to 'w' and has a buffer size 'n'.
+func NewWriterSize(w io.Writer, n int) *Writer {
+ if wr, ok := w.(*Writer); ok && cap(wr.buf) >= n {
return wr
}
+ buf := make([]byte, 0, max(n, minWriterSize))
+ return NewWriterBuf(w, buf)
+}
+
+// NewWriterBuf returns a new writer
+// that writes to 'w' and has 'buf' as a buffer.
+// 'buf' is not used when has smaller capacity than 18,
+// custom buffer is allocated instead.
+func NewWriterBuf(w io.Writer, buf []byte) *Writer {
+ if cap(buf) < minWriterSize {
+ buf = make([]byte, 0, minWriterSize)
+ }
+ buf = buf[:0]
return &Writer{
w: w,
- buf: make([]byte, 0, max(size, minWriterSize)),
+ buf: buf,
}
}