diff --git a/README.md b/README.md index 20c0b69..8c60a7d 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,11 @@ # Todo -* standalone attachments * etags * db:changes_stream * Authentication -* Write docs \ No newline at end of file +* Write docs + +## Limitiations + +* Streaming attachments is not supported at this point (patches welcome) \ No newline at end of file diff --git a/lib/couchdb.js b/lib/couchdb.js index 569a3e0..b3589ae 100644 --- a/lib/couchdb.js +++ b/lib/couchdb.js @@ -88,12 +88,16 @@ exports.createClient = function(port, host) { request.finish(function(res) { var buffer = ''; - res.setBodyEncoding('utf8'); + res.setBodyEncoding(options.responseEncoding || 'utf8'); res .addListener('body', function(chunk) { buffer += (chunk || ''); }) .addListener('complete', function() { + if(options.responseEncoding == 'binary') { + promise.emitSuccess(buffer); + } + var json; try { json = JSON.parse(buffer); @@ -344,6 +348,12 @@ Db.prototype.removeAttachment = function(docId, attachmentId, docRev) { }) }; +Db.prototype.getAttachment = function(docId, attachmentId) { + return this.request({ + path: '/'+docId+'/'+attachmentId, + responseEncoding: 'binary', + }); +}; Db.prototype.removeDoc = function(id, rev) { return this.request({ @@ -351,7 +361,7 @@ Db.prototype.removeDoc = function(id, rev) { path: '/'+id, query: {rev: rev} }); -} +}; Db.prototype.copyDoc = function(srcId, destId, destRev) { if (destRev) { diff --git a/test/test-attachment.js b/test/test-attachment.js index d0b20cb..4f663b9 100644 --- a/test/test-attachment.js +++ b/test/test-attachment.js @@ -8,6 +8,7 @@ var B: false, C: false, D: false, + E: false, }, db = client.db(DB_NAME); @@ -34,6 +35,13 @@ couchdb callbacks.B = true; assert.ok(r.ok); assert.equal('logo-doc', r.id); + + db + .getAttachment('logo-doc', 'logo.png') + .addCallback(function(r) { + callbacks.E = true; + assert.equal(3010, r.length); + }); }); });