I uploaded a png as attachment to a CouchDb database. When I have look at it via Futon it is fine, if I try to get it back via cradle it is corrupted. I used a snipptlet from the crade-test.js shipped with crade and modified it a bit:
var response = {};
var streamer = db.getAttachment(data.id,filename);
streamer.addListener('response', function (res) {
response.headers = res.headers;
response.headers.status = res.statusCode;
response.body = "";
});
streamer.addListener('data', function (chunk) { response.body += chunk; });
streamer.addListener('end', function () {
fs.writeFile('new-'+filename, response.body, function (err) {
if (err) throw err;
console.log('It\'s saved!');
});
});
The result is a corrupted png that is bigger than the input. I provided a working example here: http://jsfiddle.net/x8GZc/