Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'checksum' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
core_output.on('close', function() {
checksum.file(modules_dir + '/taracot_core.zip_', function(err, core_sum) {
async.eachSeries(modules, function(module, callback) {
// if (!module.match(/^billing_/)) {
console.log("Re-creating temp dir...");
fs.removeSync(modules_dir_tmp);
fs.ensureDir(modules_dir_tmp);
console.log("Copying " + module + " files...");
fs.copySync(production_dir + '/modules/' + module, modules_dir_tmp + '/' + module);
var core_archive = archiver('zip'),
core_output = fs.createWriteStream(modules_dir + '/taracot_' + module + '.zip');
core_archive.pipe(core_output);
console.log("Creating " + module + " update ZIP file...");
core_archive.bulk([{
expand: true,
cwd: modules_dir_tmp,
src: ['./**']
}]);
const checksummer = (resolved) => {
if (!(resolved instanceof Array)) {
resolved = [resolved]
}
console.log(tab(1) + 'Now going to generate checksums on resolved files')
for (let obj of resolved) {
if (obj.file) {
if (!Array.isArray(obj.file)) {
obj.file = [obj.file]
}
for (let filePath of obj.file) {
// TODO handle errors better
checksum.file(filePath, (err, sum) => {
if (err) {
console.log('ERROR: ', err)
return
}
let stats
try {
stats = fs.statSync(filePath)
} catch(err) {
console.log('ERROR: ', err)
}
const objDetails = {}
objDetails[filePath] = {
hash: sum,
fs.access(path.join(file.path, path.basename(file.url)), err => {
if (err) {
reject(err);
} else {
if (!file.checksum) {
// No checksum so return true;
resolve();
return;
} else {
checksum.file(
path.join(file.path, path.basename(file.url)),
{
algorithm: "sha256"
},
function(err, sum) {
utils.log.debug(
"checked: " + path.basename(file.url),
sum === file.checksum
);
if (sum === file.checksum) {
resolve();
} else {
reject(
new Error(
"checksum mismatch: calculated " +
sum +
}).catch(fail)
}
if (torrentData && torrentData.infoHash) {
const iHash = torrentData.infoHash
const appDataFastResume = path.join(fastResumeDir, iHash + '.fastresume')
const removeFastResume = () => {
fs.unlink(appDataFastResume, () => {
startTorrent()
})
}
if (fs.existsSync(appDataFastResume)) {
checksum.file(appDataFastResume, function (err, sum) {
if (!err && sum) {
const fastBook = fastresumebook.get(iHash)
if (fastBook && fastBook.sum) {
if (fastBook.sum == sum) {
// checksum of fast resume file correct, continue
startTorrent()
} else {
// checksum incorrect, remove
removeFastResume()
}
} else {
// checksum incorrect, remove
removeFastResume()
}
} else {
return new Promise((resolve, reject) => {
checksum.file(file, { algorithm: 'sha256' }, (_: any, hash: string) => {
if (hash !== expected) {
console.log(`checksum failed: got '${hash}' but expected '${expected}'`)
}
resolve(hash === expected)
})
})
}
async.eachSeries(zip_files, function(file, callback) {
checksum.file(file, function(err, sum) {
if (err || !sum) return callback(err || "Failed to get checksum for " + file);
taracot_info[modules[cnt]].checksum = sum;
cnt++;
callback();
});
}, function(err) {
if (err) return console.log(err);
checksum.file(configFileName, (err, sum) => {
if (sum !== checksum(newNginxConf)) {
reloadNginxConfig(newNginxConf)
} else {
console.log("Nginx config was unchanged");
}
});
}
return await new Promise((resolve, reject) => {
checksum.file(file, (error, hash) => {
if (error) reject(error)
else resolve(hash)
})
})
}
return new Promise(resolve => {
checksum.file(file, (err, sum) => resolve(hash === sum));
});
}