Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: go/src/infra/libs/infra_util/buf.go

Issue 662113003: Drover's back, baby! (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git/+/master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 package infra_util
2
3 import "io"
4
5 type Nomable interface {
6 ReadString(delim byte) (string, error)
7 }
8
9 // Returns `func(byte) string` which will read from |buf| until the byte,
10 // returning the string read. If an error is encountered, this will panic.
11 func Nom(buf Nomable) func(byte) string {
12 return func(delim byte) string {
13 ret, err := buf.ReadString(delim)
14 if err != nil {
15 panic(err)
16 }
17 return ret[:len(ret)-1]
18 }
19 }
20
21 // Returns `func (int) []byte` which will read the specified number of bytes
22 // from |buf|, or panic.
23 func Yoink(buf io.Reader) func(int) []byte {
24 return func(num int) []byte {
25 ret := make([]byte, num)
26 i, err := io.ReadFull(buf, ret)
27 if err != nil {
28 panic(err)
29 }
30 if i != len(ret) {
31 panic("yoink: failed to read enough data")
32 }
33 return ret
34 }
35 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698