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

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: Lots of fixes 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 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 package infra_util
5
6 import (
7 "io"
8 )
9
10 type Nomable interface {
11 ReadString(delim byte) (string, error)
12 }
13
14 // Returns `func(byte) string` which will read from |buf| until the byte,
15 // returning the string read. If an error is encountered, this will panic.
16 func Nom(buf Nomable) func(byte) string {
17 return func(delim byte) string {
18 ret, err := buf.ReadString(delim)
19 if err != nil {
20 panic(err)
21 }
22 return ret[:len(ret)-1]
23 }
24 }
25
26 // Returns `func (int) []byte` which will read the specified number of bytes
27 // from |buf|, or panic.
28 func Yoink(buf io.Reader) func(int) []byte {
Vadim Sh. 2014/10/21 15:27:00 " An exclamation that, when uttered in conjunction
29 return func(num int) []byte {
30 ret := make([]byte, num)
31 i, err := io.ReadFull(buf, ret)
32 if err != nil {
33 panic(err)
34 }
35 if i != len(ret) {
36 panic("yoink: failed to read enough data")
37 }
38 return ret
39 }
40 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698