MCPcopy Create free account
hub / github.com/imroc/req / readLineSlice

Method readLineSlice

textproto_reader.go:82–103  ·  view source on GitHub ↗

readLineSlice reads a single line from r, up to lim bytes long (or unlimited if lim is less than 0), eliding the final \r or \r\n from the returned string.

(lim int64)

Source from the content-addressed store, hash-verified

80// up to lim bytes long (or unlimited if lim is less than 0),
81// eliding the final \r or \r\n from the returned string.
82func (r *textprotoReader) readLineSlice(lim int64) ([]byte, error) {
83 var line []byte
84
85 for {
86 l, more, err := r.readLine()
87 if err != nil {
88 return nil, err
89 }
90 if lim >= 0 && int64(len(line))+int64(len(l)) > lim {
91 return nil, errMessageTooLarge
92 }
93 // Avoid the copy if the first call produced a full line.
94 if line == nil && !more {
95 return l, nil
96 }
97 line = append(line, l...)
98 if !more {
99 break
100 }
101 }
102 return line, nil
103}
104
105// trim returns s with leading and trailing spaces and tabs removed.
106// It does not assume Unicode or UTF-8.

Callers 3

ReadLineMethod · 0.95
readMIMEHeaderMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected