couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [11/25] couch commit: updated refs/heads/master to 92598cd
Date Thu, 15 Oct 2015 16:35:45 GMT
Extract encode_multipart_stream function out of doc_to_multi_part_stream


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/dbf8b983
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/dbf8b983
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/dbf8b983

Branch: refs/heads/master
Commit: dbf8b983e76a88f2dcb866e2e75621552f21846e
Parents: 4abf06e
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Fri Nov 28 10:34:36 2014 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Wed May 6 06:55:58 2015 -0700

----------------------------------------------------------------------
 src/couch_doc.erl | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/dbf8b983/src/couch_doc.erl
----------------------------------------------------------------------
diff --git a/src/couch_doc.erl b/src/couch_doc.erl
index 3a25ac5..bcd278c 100644
--- a/src/couch_doc.erl
+++ b/src/couch_doc.erl
@@ -407,22 +407,15 @@ len_doc_to_multi_part_stream(Boundary, JsonBytes, Atts, SendEncodedAtts)
->
 
 doc_to_multi_part_stream(Boundary, JsonBytes, Atts, WriteFun,
     SendEncodedAtts) ->
-    case lists:any(fun(Att)-> couch_att:fetch(data, Att) /= stub end, Atts) of
-    true ->
-        WriteFun([<<"--", Boundary/binary,
-                "\r\nContent-Type: application/json\r\n\r\n">>,
-                JsonBytes, <<"\r\n--", Boundary/binary>>]),
-        atts_to_mp(Atts, Boundary, WriteFun, SendEncodedAtts);
-    false ->
-        WriteFun(JsonBytes)
-    end.
+    AttsToInclude = lists:filter(fun(Att)-> couch_att:fetch(data, Att) /= stub end, Atts),
+    encode_multipart_stream(Boundary, JsonBytes, AttsToInclude, WriteFun, SendEncodedAtts).
 
 atts_to_mp([], _Boundary, WriteFun, _SendEncAtts) ->
     WriteFun(<<"--">>);
 atts_to_mp([Att | RestAtts], Boundary, WriteFun, SendEncodedAtts)  ->
     case couch_att:is_stub(Att) of
         true ->
-            atts_to_mp(RestAtts, Boundary, WriteFun, SendEncodedAtts);
+            unreacheable = atts_to_mp(RestAtts, Boundary, WriteFun, SendEncodedAtts);
         false ->
             [Name, AttLen, DiskLen, Type, Encoding] =
                 couch_att:fetch([name, att_len, disk_len, type, encoding], Att),
@@ -453,6 +446,14 @@ atts_to_mp([Att | RestAtts], Boundary, WriteFun, SendEncodedAtts)  ->
             atts_to_mp(RestAtts, Boundary, WriteFun, SendEncodedAtts)
     end.
 
+encode_multipart_stream(_Boundary, JsonBytes, [], WriteFun, _SendEncodedAtts) ->
+    WriteFun(JsonBytes);
+encode_multipart_stream(Boundary, JsonBytes, Atts, WriteFun, SendEncodedAtts) ->
+    WriteFun([<<"--", Boundary/binary,
+                "\r\nContent-Type: application/json\r\n\r\n">>,
+              JsonBytes, <<"\r\n--", Boundary/binary>>]),
+    atts_to_mp(Atts, Boundary, WriteFun, SendEncodedAtts).
+
 doc_from_multi_part_stream(ContentType, DataFun) ->
     doc_from_multi_part_stream(ContentType, DataFun, make_ref()).
 


Mime
View raw message