You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2011/05/26 14:07:20 UTC

svn commit: r1127879 - /couchdb/trunk/src/couchdb/couch_db.erl

Author: rnewson
Date: Thu May 26 12:07:19 2011
New Revision: 1127879

URL: http://svn.apache.org/viewvc?rev=1127879&view=rev
Log:
COUCHDB-1177 - don't read more of an attachment than Content-Length states.

(original patch by Paul Davis, awesomeness enhanced by Robert Newson).

Conflicts:

	src/couchdb/couch_httpd_db.erl

Modified:
    couchdb/trunk/src/couchdb/couch_db.erl

Modified: couchdb/trunk/src/couchdb/couch_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_db.erl?rev=1127879&r1=1127878&r2=1127879&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_db.erl Thu May 26 12:07:19 2011
@@ -998,10 +998,15 @@ with_stream(Fd, #att{md5=InMd5,type=Type
 write_streamed_attachment(_Stream, _F, 0) ->
     ok;
 write_streamed_attachment(Stream, F, LenLeft) when LenLeft > 0 ->
-    Bin = F(lists:min([LenLeft, 16#2000])),
+    Bin = read_next_chunk(F, LenLeft),
     ok = couch_stream:write(Stream, Bin),
     write_streamed_attachment(Stream, F, LenLeft - size(Bin)).
 
+read_next_chunk(F, _) when is_function(F, 0) ->
+    F();
+read_next_chunk(F, LenLeft) when is_function(F, 1) ->
+    F(lists:min([LenLeft, 16#2000])).
+
 enum_docs_since_reduce_to_count(Reds) ->
     couch_btree:final_reduce(
             fun couch_db_updater:btree_by_seq_reduce/2, Reds).