Archived
1
0
This repository has been archived on 2023-08-12. You can view files and clone it, but cannot push or open issues or pull requests.
nntpchan/contrib/backends/srndv2/src/srnd/line.go
2017-04-04 11:04:14 -04:00

35 lines
505 B
Go

package srnd
import (
"bytes"
"io"
)
type LineWriter struct {
w io.Writer
Left int64
}
func NewLineWriter(w io.Writer, limit int64) *LineWriter {
return &LineWriter{
w: w,
Left: limit,
}
}
func (l *LineWriter) Write(data []byte) (n int, err error) {
if l.Left <= 0 {
err = ErrOversizedMessage
return
}
wr := len(data)
data = bytes.Replace(data, []byte{13, 10}, []byte{10}, -1)
n, err = l.w.Write(data)
l.Left -= int64(n)
if err != nil {
return n, err
}
n = wr
return
}