mercurial/util.py
changeset 35754 fb0be099063f
parent 35582 72b91f905065
child 35755 2384523cee4d
--- a/mercurial/util.py	Fri Jan 19 19:13:11 2018 -0500
+++ b/mercurial/util.py	Fri Jan 19 20:51:35 2018 +0100
@@ -3865,3 +3865,12 @@
         fn = '%s~%s~%s' % (f, tag, n)
         if fn not in ctx and fn not in others:
             return fn
+
+def readexactly(stream, n):
+    '''read n bytes from stream.read and abort if less was available'''
+    s = stream.read(n)
+    if len(s) < n:
+        raise error.Abort(_("stream ended unexpectedly"
+                           " (got %d bytes, expected %d)")
+                          % (len(s), n))
+    return s