summaryrefslogtreecommitdiff
path: root/lib/git/odb/fun.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2010-06-04 23:06:31 +0200
committerSebastian Thiel <byronimo@gmail.com>2010-06-04 23:06:31 +0200
commita243827ab3346e188e99db2f9fc1f916941c9b1a (patch)
treee0111a983c83efb616dcbbe9aa453d5c54b3b90e /lib/git/odb/fun.py
parent6fbb69306c0e14bacb8dcb92a89af27d3d5d631f (diff)
downloadgitpython-a243827ab3346e188e99db2f9fc1f916941c9b1a.tar.gz
Implemented stream tests, found a bug on the way, slowly a test-framework for streams starts to show up, but its not yet there
Diffstat (limited to 'lib/git/odb/fun.py')
-rw-r--r--lib/git/odb/fun.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/git/odb/fun.py b/lib/git/odb/fun.py
index 870a6f02..3321a8ea 100644
--- a/lib/git/odb/fun.py
+++ b/lib/git/odb/fun.py
@@ -83,26 +83,33 @@ def write_object(type, size, read, write, chunk_size=chunk_size):
:param size: amount of bytes to write from source_stream
:param read: read method of a stream providing the content data
:param write: write method of the output stream
- :param close_target_stream: if True, the target stream will be closed when
+ :param close_target_stream: if True, the target stream will be closed when
the routine exits, even if an error is thrown
:return: The actual amount of bytes written to stream, which includes the header and a trailing newline"""
tbw = 0 # total num bytes written
- dbw = 0 # num data bytes written
# WRITE HEADER: type SP size NULL
tbw += write("%s %i\0" % (type, size))
+ tbw += stream_copy(read, write, size, chunk_size)
+
+ return tbw
+def stream_copy(read, write, size, chunk_size):
+ """Copy a stream up to size bytes using the provided read and write methods,
+ in chunks of chunk_size
+ :note: its much like stream_copy utility, but operates just using methods"""
+ dbw = 0 # num data bytes written
+
# WRITE ALL DATA UP TO SIZE
while True:
cs = min(chunk_size, size-dbw)
data_len = write(read(cs))
dbw += data_len
if data_len < cs or dbw == size:
- tbw += dbw
break
# END check for stream end
# END duplicate data
- return tbw
-
+ return dbw
+
#} END routines