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

Unified 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: more tests and refactors 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « go/src/infra/libs/gitiles/statusError.go ('k') | go/src/infra/libs/infra_util/errors.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/libs/infra_util/buf.go
diff --git a/go/src/infra/libs/infra_util/buf.go b/go/src/infra/libs/infra_util/buf.go
new file mode 100644
index 0000000000000000000000000000000000000000..fda55b6b474a94b5e165723dedb04c5e159024cc
--- /dev/null
+++ b/go/src/infra/libs/infra_util/buf.go
@@ -0,0 +1,41 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package infra_util
+
+import (
+ "io"
+)
+
+type Nomable interface {
+ ReadString(delim byte) (string, error)
+}
+
+// Returns `func(byte) string` which will read from |buf| until the byte,
+// returning the string read. If an error is encountered, this will panic.
+func Nom(buf Nomable) func(byte) string {
+ return func(delim byte) string {
+ ret, err := buf.ReadString(delim)
+ if err != nil {
+ panic(err)
+ }
+ return ret[:len(ret)-1]
+ }
+}
+
+// Returns `func (int) []byte` which will read the specified number of bytes
+// from |buf|, or panic.
+func Yoink(buf io.Reader) func(int) []byte {
+ return func(num int) []byte {
+ ret := make([]byte, num)
+ i, err := io.ReadFull(buf, ret)
+ if err != nil {
+ panic(err)
+ }
+ if i != len(ret) {
+ panic("yoink: failed to read enough data")
+ }
+ return ret
+ }
+}
« no previous file with comments | « go/src/infra/libs/gitiles/statusError.go ('k') | go/src/infra/libs/infra_util/errors.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698