mercurial/changegroup.py
changeset 3660 8500a13ec44b
parent 3659 025f68f22ae2
child 3662 f4dc02d7fb71
--- a/mercurial/changegroup.py	Wed Nov 15 15:51:58 2006 -0600
+++ b/mercurial/changegroup.py	Wed Nov 15 15:51:58 2006 -0600
@@ -93,3 +93,23 @@
             fh.close()
         if cleanup is not None:
             os.unlink(cleanup)
+
+def readbundle(fh):
+    header = fh.read(6)
+    if not header.startswith("HG"):
+        raise util.Abort(_("%s: not a Mercurial bundle file") % fname)
+    elif not header.startswith("HG10"):
+        raise util.Abort(_("%s: unknown bundle version") % fname)
+
+    if header == "HG10BZ":
+        def generator(f):
+            zd = bz2.BZ2Decompressor()
+            zd.decompress("BZ")
+            for chunk in util.filechunkiter(f, 4096):
+                yield zd.decompress(chunk)
+        return util.chunkbuffer(generator(fh))
+    elif header == "HG10UN":
+        return fh
+
+    raise util.Abort(_("%s: unknown bundle compression type")
+                     % fname)