2023-01-11 11:13:13 +00:00
|
|
|
package iotools
|
|
|
|
|
|
|
|
import "io"
|
|
|
|
|
|
|
|
// WriterFunc is a function signature which allows
|
|
|
|
// a function to implement the io.Writer type.
|
|
|
|
type WriterFunc func([]byte) (int, error)
|
|
|
|
|
|
|
|
func (w WriterFunc) Write(b []byte) (int, error) {
|
|
|
|
return w(b)
|
|
|
|
}
|
|
|
|
|
2023-10-31 11:12:22 +00:00
|
|
|
// WriterToFunc is a function signature which allows
|
|
|
|
// a function to implement the io.WriterTo type.
|
|
|
|
type WriterToFunc func(io.Writer) (int64, error)
|
|
|
|
|
|
|
|
func (wt WriterToFunc) WriteTo(r io.Writer) (int64, error) {
|
|
|
|
return wt(r)
|
|
|
|
}
|
|
|
|
|
2023-01-11 11:13:13 +00:00
|
|
|
// WriteCloser wraps an io.Writer and io.Closer in order to implement io.WriteCloser.
|
|
|
|
func WriteCloser(w io.Writer, c io.Closer) io.WriteCloser {
|
|
|
|
return &struct {
|
|
|
|
io.Writer
|
|
|
|
io.Closer
|
|
|
|
}{w, c}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NopWriteCloser wraps an io.Writer to implement io.WriteCloser with empty io.Closer implementation.
|
|
|
|
func NopWriteCloser(w io.Writer) io.WriteCloser {
|
2024-07-12 09:39:47 +00:00
|
|
|
return &nopWriteCloser{w}
|
2023-01-11 11:13:13 +00:00
|
|
|
}
|
2024-07-12 09:39:47 +00:00
|
|
|
|
|
|
|
// nopWriteCloser implements io.WriteCloser with a no-op Close().
|
|
|
|
type nopWriteCloser struct{ io.Writer }
|
|
|
|
|
|
|
|
func (wc *nopWriteCloser) Close() error { return nil }
|