Skip to content

Commit

Permalink
getAttachment()
Browse files Browse the repository at this point in the history
  • Loading branch information
felixge committed Feb 3, 2010
1 parent 1a06fc8 commit 62d4cfc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -2,8 +2,11 @@

# Todo

* standalone attachments
* etags
* db:changes_stream
* Authentication
* Write docs
* Write docs

## Limitiations

* Streaming attachments is not supported at this point (patches welcome)
14 changes: 12 additions & 2 deletions lib/couchdb.js
Expand Up @@ -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);
Expand Down Expand Up @@ -344,14 +348,20 @@ 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({
method: 'DELETE',
path: '/'+id,
query: {rev: rev}
});
}
};

Db.prototype.copyDoc = function(srcId, destId, destRev) {
if (destRev) {
Expand Down
8 changes: 8 additions & 0 deletions test/test-attachment.js
Expand Up @@ -8,6 +8,7 @@ var
B: false,
C: false,
D: false,
E: false,
},

db = client.db(DB_NAME);
Expand All @@ -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);
});
});
});

Expand Down

0 comments on commit 62d4cfc

Please sign in to comment.