dominicbarnes/node-couchdb-api — pull request #11 by mugami-ast (2012-06-08 10:28:41+00:00)
Title: Fix JSON.parsing when streaming changes

When streaming a lot of changes, a chunk might only be a partial JSON string, which results in the current code throwing a syntax error.

Refactor proto._stream()
--------------------------------
commit 4fe50608488b9d2c0419ffd099a9aa73b867056f

The goal of this patch is to remove noise from the next patch.

Reasoning:
- JSON.parse takes a string as input, therefore clearly reject
non-strings.
- Since we now know that chunk is a string, directly check the length.

lib/client.js | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)

Handle JSON errors in proto._stream()
--------------------------------------------------
commit c901c234aa4f515ec5f0226c3542aeffc81fabeb

In order To handle partial JSON chunks, use a buffer, and only emit a
parse error if the buffer remains unparsable for the whole period
defined by the new error_timeout option (default: 500ms).

lib/client.js | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)