Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function readBlobData(body, type, asBlob, callback) {
if (asBlob) {
if (!body) {
callback(createBlob([''], {type: type}));
} else if (typeof body !== 'string') { // we have blob support
callback(body);
} else { // no blob support
callback(b64StringToBlob(body, type));
}
} else { // as base64 string
if (!body) {
callback('');
} else if (typeof body !== 'string') { // we have blob support
readAsBinaryString(body, function (binary) {
callback(btoa(binary));
});
} else { // no blob support
callback(body);
}
}
}
Object.keys(doc._attachments).forEach(key => {
const newAttachment = {
...attachmentObj[doc._attachments[key].digest]
}
if (newAttachment) {
doc._attachments[key] = newAttachment
if (binaryAttachments) {
const contentType = doc._attachments[key].content_type
doc._attachments[key].data = base64StringToBlobOrBuffer(
doc._attachments[key].data,
contentType
)
}
}
})
})
Object.keys(atts).forEach(function (filename) {
var att = atts[filename];
atts[filename].data = b64ToBluffer(att.data, att.content_type);
});
});
db.storage.get(forAttachment(digest), (error, attachmentData) => {
if (error) {
return callback(
createError(MISSING_DOC, error.message || 'missing-read-error')
)
}
const data = attachmentData.data
if (opts.binary) {
callback(null, base64StringToBlobOrBuffer(data, type))
} else {
callback(null, data)
}
})
}
Object.keys(atts).forEach(function (filename) {
var att = atts[filename];
att.data = b64StringToBluffer(att.data, att.content_type);
});
}