2023-04-11 22:20:37 +03:00
|
|
|
package buf // import "go.unistack.org/micro/v4/util/buf"
|
2015-01-14 02:31:27 +03:00
|
|
|
|
|
|
|
import (
|
2015-11-28 14:22:29 +03:00
|
|
|
"bytes"
|
2022-01-10 16:47:37 +03:00
|
|
|
"io"
|
2015-01-14 02:31:27 +03:00
|
|
|
)
|
|
|
|
|
2022-01-10 16:47:37 +03:00
|
|
|
var _ io.Closer = &Buffer{}
|
|
|
|
|
|
|
|
// Buffer bytes.Buffer wrapper to satisfie io.Closer interface
|
2021-04-27 08:32:47 +03:00
|
|
|
type Buffer struct {
|
2015-11-28 14:22:29 +03:00
|
|
|
*bytes.Buffer
|
2015-01-14 02:31:27 +03:00
|
|
|
}
|
|
|
|
|
2021-02-14 16:16:01 +03:00
|
|
|
// Close reset buffer contents
|
2021-04-27 08:32:47 +03:00
|
|
|
func (b *Buffer) Close() error {
|
2015-11-28 14:22:29 +03:00
|
|
|
b.Buffer.Reset()
|
2015-01-14 02:31:27 +03:00
|
|
|
return nil
|
|
|
|
}
|
2019-07-28 21:33:24 +03:00
|
|
|
|
2021-02-14 16:16:01 +03:00
|
|
|
// New creates new buffer that satisfies Closer interface
|
2021-04-27 08:32:47 +03:00
|
|
|
func New(b *bytes.Buffer) *Buffer {
|
2019-07-28 21:33:24 +03:00
|
|
|
if b == nil {
|
|
|
|
b = bytes.NewBuffer(nil)
|
|
|
|
}
|
2021-04-27 08:32:47 +03:00
|
|
|
return &Buffer{b}
|
2019-07-28 21:33:24 +03:00
|
|
|
}
|