21 lines
322 B
Go
21 lines
322 B
Go
|
package main
|
||
|
|
||
|
import "io"
|
||
|
|
||
|
func NewWriterFromByteChan(ch chan byte) *ByteChanWriter {
|
||
|
return &ByteChanWriter{ch}
|
||
|
}
|
||
|
|
||
|
type ByteChanWriter struct {
|
||
|
ch chan byte
|
||
|
}
|
||
|
|
||
|
var _ io.Writer = &ByteChanWriter{}
|
||
|
|
||
|
func (w *ByteChanWriter) Write(p []byte) (n int, err error) {
|
||
|
for _, b := range p {
|
||
|
w.ch <- b
|
||
|
}
|
||
|
return len(p), nil
|
||
|
}
|