anchor.diff:              Reason = proplists:get_value(<<"reason">>, Props),
               {{Id, Rev}, {ErrId, Reason}}
           end, ErrorsJson),
  -    receive
  -    {docs_remaining, 0} ->
  -        {ok, lists:flatten([ErrorsList|ErrorsAcc])};
  -    {docs_remaining, N} ->
  -        MoreDocs = lists:nthtail(length(Docs)-N, Docs),
  -        write_docs(Db, MoreDocs, [ErrorsList|ErrorsAcc])
  -    end;
  -write_docs(Db, Docs, _) ->
  +    {ok, ErrorsList};
  +write_docs(Db, Docs) ->
       couch_db:update_docs(Db, Docs, [], replicated_changes).
  
positive.code: -include("couch_db.hrl").
  
  -define (MAX_BYTES, 10000000).
  
  start_link(Parent, Target, Reader, _PostProps) ->
      {ok, spawn_link(fun() -> writer_loop(Parent, Reader, Target) end)}.
  
  make_chunk(Data) when is_list(Data) ->
      make_chunk(list_to_binary(Data));
  make_chunk(Data) ->
      Size = size(Data),
      {Size, [ibrowse_lib:dec2hex(8, Size), "\r\n", Data, "\r\n"]}.
  
  upload_docs({start, W, Docs}) ->
      {Size, Chunk} = make_chunk(<<"{\"new_edits\":false, \"docs\":[">>),
      {ok, Chunk, {continue, W, Docs, "", Size}};
  upload_docs({continue, W, Docs, _, ByteCount}) when ByteCount > ?MAX_BYTES ->
      W ! {docs_remaining, length(Docs)},
      {ok, "2\r\n]}\r\n", last_chunk};
  upload_docs({continue, W, [Doc|Rest], Prepend, ByteCount}) ->
      JsonDoc = ?JSON_ENCODE(couch_doc:to_json_obj(Doc, [revs,attachments])),
      {Size, Chunk} = make_chunk([Prepend, JsonDoc]),
      {ok, Chunk, {continue, W, Rest, ",", ByteCount+Size}};
  upload_docs({continue, W, [], _, _}) ->
      W ! {docs_remaining, 0},
      {ok, "2\r\n]}\r\n", last_chunk};
  upload_docs(last_chunk) ->
      {ok, "0\r\n\r\n", finish};
  upload_docs(finish) ->
      couch_util:should_flush(),
      eof.
      
  writer_loop(Parent, Reader, Target) ->
      case couch_rep_reader:next(Reader) of
      {complete, FinalSeq} ->
  
negative.code:         writer_loop(Parent, Reader, Target)
      end.
  
  write_docs(#http_db{} = Db, Docs) ->
      {Worker, Ref} = spawn_monitor(fun() -> encoding_worker(Docs) end),
      Pid = spawn_link(fun() -> Worker ! {self(),next_doc}, middle_man(Worker) end),
      Request = Db#http_db{
          resource = "_bulk_docs",
          method = post,
          body = {fun upload_docs/1, {start, Pid}},
          headers = [{"transfer-encoding", "chunked"} | Db#http_db.headers]
      },
      ErrorsJson = request_loop(Ref, Request, []),
      ErrorsList =
      lists:map(
          fun({Props}) ->
  