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);
}
}
}
function parseAttachment(attachment, opts, cb) {
if (opts.binary) {
return cb(null, attachment);
} else {
readAsBinaryString(attachment, function (binString) {
cb(null, btoa(binString));
});
}
}
db.storage.get(keys.forDocument(docId), (error, doc) => {
if (error) {
return callback(createError(
MISSING_DOC, error.message || 'missing-read-error'))
}
const rev = opts.rev ? doc.revs[opts.rev].data : doc.data
const digest = rev._attachments[attachId].digest
if (opts.binary) {
return callback(null, doc.attachments[digest].data)
}
readAsBinaryString(doc.attachments[digest].data, binString => {
callback(null, btoa(binString))
})
})
}
function prepareAttachmentForStorage(attData, cb) {
readAsBinaryString(attData, cb);
}
function prepareAttachmentForStorage(attData, cb) {
pouchdbBinaryUtils.readAsBinaryString(attData, cb);
}
function prepareAttachmentForStorage(attData, cb) {
readAsBinaryString(attData, cb);
}
return new Promise(function (resolve) {
var data = src.attachments[doc._attachments[name].digest].data;
readAsBinaryString(data, function (binString) {
doc._attachments[name].data = btoa(binString);
delete doc._attachments[name].length;
resolve();
});
});
}