couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [10/25] couch commit: updated refs/heads/master to 92598cd
Date Thu, 15 Oct 2015 16:35:44 GMT
Move encode_multipart_stream from couch_doc into couch_httpd_multipart


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

Branch: refs/heads/master
Commit: 3d6c147e3643c6aace20a3f12aa0fc154d21e1bf
Parents: 13d8e42
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Fri Nov 28 11:36:59 2014 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Wed May 6 06:55:58 2015 -0700

----------------------------------------------------------------------
 src/couch_doc.erl             | 33 ++-------------------------------
 src/couch_httpd_multipart.erl | 30 ++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/3d6c147e/src/couch_doc.erl
----------------------------------------------------------------------
diff --git a/src/couch_doc.erl b/src/couch_doc.erl
index 40412ad..edca1fc 100644
--- a/src/couch_doc.erl
+++ b/src/couch_doc.erl
@@ -421,37 +421,8 @@ doc_to_multi_part_stream(Boundary, JsonBytes, Atts, WriteFun,
         false -> fun couch_att:foldl_decode/3;
         true  -> fun couch_att:foldl/3
     end,
-    encode_multipart_stream(Boundary, JsonBytes, AttsDecoded, WriteFun, AttFun).
-
-atts_to_mp([], _Boundary, WriteFun, _AttFun) ->
-    WriteFun(<<"--">>);
-atts_to_mp([{Att, Name, LengthBin, Type, Encoding} | RestAtts], Boundary, WriteFun,
-    AttFun)  ->
-    % write headers
-    WriteFun(<<"\r\nContent-Disposition: attachment; filename=\"", Name/binary, "\"">>),
-    WriteFun(<<"\r\nContent-Type: ", Type/binary>>),
-    WriteFun(<<"\r\nContent-Length: ", LengthBin/binary>>),
-    case Encoding of
-        identity ->
-            ok;
-        _ ->
-            EncodingBin = atom_to_binary(Encoding, latin1),
-            WriteFun(<<"\r\nContent-Encoding: ", EncodingBin/binary>>)
-    end,
-
-    % write data
-    WriteFun(<<"\r\n\r\n">>),
-    AttFun(Att, fun(Data, _) -> WriteFun(Data) end, ok),
-    WriteFun(<<"\r\n--", Boundary/binary>>),
-    atts_to_mp(RestAtts, Boundary, WriteFun, AttFun).
-
-encode_multipart_stream(_Boundary, JsonBytes, [], WriteFun, _AttFun) ->
-    WriteFun(JsonBytes);
-encode_multipart_stream(Boundary, JsonBytes, Atts, WriteFun, AttFun) ->
-    WriteFun([<<"--", Boundary/binary,
-                "\r\nContent-Type: application/json\r\n\r\n">>,
-              JsonBytes, <<"\r\n--", Boundary/binary>>]),
-    atts_to_mp(Atts, Boundary, WriteFun, AttFun).
+    couch_httpd_multipart:encode_multipart_stream(
+      Boundary, JsonBytes, AttsDecoded, WriteFun, AttFun).
 
 doc_from_multi_part_stream(ContentType, DataFun) ->
     doc_from_multi_part_stream(ContentType, DataFun, make_ref()).

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/3d6c147e/src/couch_httpd_multipart.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_multipart.erl b/src/couch_httpd_multipart.erl
index 1110751..17649e7 100644
--- a/src/couch_httpd_multipart.erl
+++ b/src/couch_httpd_multipart.erl
@@ -1,5 +1,6 @@
 -module(couch_httpd_multipart).
 
+-export([encode_multipart_stream/5]).
 -export([parse_multipart_stream/3]).
 -export([abort_multi_part_stream/1]).
 
@@ -160,6 +161,35 @@ num_mp_writers() ->
         Count -> Count
     end.
 
+encode_multipart_stream(_Boundary, JsonBytes, [], WriteFun, _AttFun) ->
+    WriteFun(JsonBytes);
+encode_multipart_stream(Boundary, JsonBytes, Atts, WriteFun, AttFun) ->
+    WriteFun([<<"--", Boundary/binary,
+                "\r\nContent-Type: application/json\r\n\r\n">>,
+              JsonBytes, <<"\r\n--", Boundary/binary>>]),
+    atts_to_mp(Atts, Boundary, WriteFun, AttFun).
+
+atts_to_mp([], _Boundary, WriteFun, _AttFun) ->
+    WriteFun(<<"--">>);
+atts_to_mp([{Att, Name, LengthBin, Type, Encoding} | RestAtts], Boundary, WriteFun,
+    AttFun)  ->
+    % write headers
+    WriteFun(<<"\r\nContent-Disposition: attachment; filename=\"", Name/binary, "\"">>),
+    WriteFun(<<"\r\nContent-Type: ", Type/binary>>),
+    WriteFun(<<"\r\nContent-Length: ", LengthBin/binary>>),
+    case Encoding of
+        identity ->
+            ok;
+        _ ->
+            EncodingBin = atom_to_binary(Encoding, latin1),
+            WriteFun(<<"\r\nContent-Encoding: ", EncodingBin/binary>>)
+    end,
+
+    % write data
+    WriteFun(<<"\r\n\r\n">>),
+    AttFun(Att, fun(Data, _) -> WriteFun(Data) end, ok),
+    WriteFun(<<"\r\n--", Boundary/binary>>),
+    atts_to_mp(RestAtts, Boundary, WriteFun, AttFun).
 
 abort_multi_part_stream(Parser) ->
     MonRef = erlang:monitor(process, Parser),


Mime
View raw message