Skip to content

Commit

Permalink
use buffer in saveDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
nrstott committed Dec 15, 2011
1 parent 6aeefcd commit 450077b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/couchdb.js
Expand Up @@ -428,7 +428,8 @@ Database.prototype.getAttachmentResponse = function(doc, attachmentName){
Database.prototype.saveDoc = function(doc, opts) {
var self = this
, method = httpMethod.PUT
, path = "/";
, path = "/"
, buf;

return Q.when(doc, function(doc) {
if (doc._id === undefined) {
Expand All @@ -448,12 +449,14 @@ Database.prototype.saveDoc = function(doc, opts) {
opts = { bulk : true };
}
}

buf = new Buffer(JSON.stringify(doc), 'utf-8');

return self.request({
appendName: (opts && opts.bulk) ? "/_bulk_docs" : "", // Define factor appended to DB name.
method: method,
pathname: path,
body: typeof doc === "string" ? [doc] : [JSON.stringify(doc)]
body: typeof doc === "string" ? [doc] : buf
});
});
};
Expand Down

0 comments on commit 450077b

Please sign in to comment.