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
Jeff Becker b919c095a8
fix
2017-11-07 13:37:22 -05:00

30 lines
456 B
Go

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