Streamable multipart `_attachments`
stevebest opened this issue · comments
request
has no trouble sending multipart/related
payloads from ReadableStream
s, as long as you provide the Content-Length
for it. But db.multipart.insert
doesn't support streams, because it expects only Buffer
s and strings to be attached, and prefers to calculate payload size implicitly. This is obviously problematic when you want to attach multiple huge files at once. (Yeah, I know I shouldn't abuse CouchDB like that, but I still do.)
I propose extending interface of db.multipart.insert
to allow following:
var data = fs.createReadStream('rabbit.png'); // why read the whole file when you can stream it?
var length = fs.statSync('rabbit.png').size; // or however you get the size of payload
alice.multipart.insert({ foo: 'bar' }, [{name: 'rabbit.png', data: data, length: length, content_type: 'image/png'}], 'mydoc', function(err, body) {
if (!err)
console.log(body);
});
i.e., allow passing .length
explicitly as part of attachment object. Pass it further down to request
- and it will happily accept data
in form of a stream.
Started a PR #300
Based on the comments on the pull request, it seems that this issue is not relevant anymore (unless CouchDB 1.7+ is required). If so, could you close this issue?
Oh, db.attachment.insert
returns a stream that you can .pipe()
into? That's cool.
Closing.
Actually, wait a sec. CouchDB will still hang if you try and feed it Transfer-Encoding: chunked
request, which is probably the default in request
.
I will reopen in apache/couchdb-nano
.