Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (err) {
return callback(err);
}
// do not try to store empty attachments
if (data.length === 0) {
return callback(err);
}
if (!isNewAttachment) {
// small optimization - don't bother writing it again
return callback(err);
}
txn.batch([{
type: 'put',
prefix: stores.binaryStore,
key: digest,
value: bufferFrom(data, 'binary')
}]);
callback();
});
}
typeFull += `;${ meta[i]}`;
if (meta[i].indexOf('charset=') === 0) {
charset = meta[i].substring(8);
}
}
}
// defaults to US-ASCII only if type is not provided
if (!meta[0] && !charset.length) {
typeFull += ';charset=US-ASCII';
charset = 'US-ASCII';
}
// get the encoded data portion and decode URI-encoded chars
const encoding = base64 ? 'base64' : 'ascii';
const data = unescape(uri.substring(firstComma + 1));
const buffer = bufferFrom(data, encoding) as dataUriToBuffer.MimeBuffer;
// set `.type` and `.typeFull` properties to MIME type
buffer.type = type;
buffer.typeFull = typeFull;
// set the `.charset` property
buffer.charset = charset;
return buffer;
}
function typedBuffer(binString, buffType, type) {
// buffType is either 'binary' or 'base64'
var buff = bufferFrom(binString, buffType);
buff.type = type; // non-standard, but used for consistency with the browser
return buff;
}
static dataToBuffer (data) {
try {
return BufferFrom(JSON.stringify({ data }))
} catch (err) {
console.error(err)
}
}
export function encode(data) {
return bufferFrom(String(data)).toString("base64");
}
return Buffer.concat(parts.map(function (part) {
return bufferFrom(part, 'binary');
}));
}
function defaultBody() {
return bufferFrom('', 'binary');
}
export const build = (worksheets, options = {}) => {
const defaults = {
bookType: 'xlsx',
bookSST: false,
type: 'binary'
};
const workBook = new Workbook();
worksheets.forEach((worksheet) => {
const sheetName = worksheet.name || 'Sheet';
const sheetOptions = worksheet.options || {};
const sheetData = buildSheetFromMatrix(worksheet.data || [], {...options, ...sheetOptions});
workBook.SheetNames.push(sheetName);
workBook.Sheets[sheetName] = sheetData;
});
const excelData = XLSX.write(workBook, Object.assign({}, defaults, options));
return excelData instanceof Buffer ? excelData : bufferFrom(excelData, 'binary');
};
function thisBtoa(str) {
return bufferFrom(str, 'binary').toString('base64');
}