Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function preprocessString(att, blobType, callback) {
var asBinary = parseBase64(att.data);
if (asBinary.error) {
return callback(asBinary.error);
}
att.length = asBinary.length;
if (blobType === 'blob') {
att.data = binStringToBlobOrBuffer(asBinary, att.content_type);
} else if (blobType === 'base64') {
att.data = btoa(asBinary);
} else { // binary
att.data = asBinary;
}
binaryMd5(asBinary, function (result) {
att.digest = 'md5-' + result;
callback();
});
}
tx.executeSql(sql, [digest], function (tx, result) {
// websql has a bug where \u0000 causes early truncation in strings
// and blobs. to work around this, we used to use the hex() function,
// but that's not performant. after migration 6, we remove \u0000
// and add it back in afterwards
var item = result.rows.item(0);
var data = item.escaped ? unescapeBlob(item.body) :
parseHexString(item.body, encoding);
if (opts.binary) {
res = binStringToBlob(data, type);
} else {
res = btoa(data);
}
callback(null, res);
});
};
readAsBinaryString(body, function (binary) {
callback(btoa(binary));
});
} else { // no blob support
var ourFetch = function (url, options) {
options = options || {};
options.headers = options.headers || new Headers();
options.credentials = 'include';
if (opts.auth || host.auth) {
var nAuth = opts.auth || host.auth;
var str = nAuth.username + ':' + nAuth.password;
var token = btoa(unescape(encodeURIComponent(str)));
options.headers.set('Authorization', 'Basic ' + token);
}
var headers = opts.headers || {};
Object.keys(headers).forEach(function (key) {
options.headers.append(key, headers[key]);
});
/* istanbul ignore if */
if (shouldCacheBust(options)) {
url += (url.indexOf('?') === -1 ? '?' : '&') + '_nonce=' + Date.now();
}
var fetchFun = opts.fetch || fetch;
return fetchFun(url, options);
};
readAsBinaryString(doc.attachments[digest].data, binString => {
callback(null, btoa(binString))
})
})
if (db.__opts.auth) {
auth = db.__opts.auth;
} else {
var url = urlParse(db.name);
if (url.auth) {
auth = url;
}
}
if (!auth) {
return {};
}
var str = auth.username + ':' + auth.password;
var token = btoa(unescape(encodeURIComponent(str)));
return {Authorization: 'Basic ' + token};
}
function rawToBase64(raw) {
return btoa(raw);
}
readAsBinaryString(attachment, function (binString) {
cb(null, btoa(binString));
});
}
readAsBinaryString(data, function (binString) {
doc._attachments[name].data = btoa(binString);
delete doc._attachments[name].length;
resolve();
});
});