Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async verifyFile(cachedFile: string, removeIfInvalid: boolean): Promise {
if (!this.options.isVerifyChecksum) {
return true
}
debug("Verifying file with checksum")
if (!await pathExists(this.cachedChecksum)) {
await this.downloadFile(this.checksumUrl, this.cachedChecksum)
}
const checker = new ChecksumValidator("sha256", this.cachedChecksum)
try {
await checker.validate(path.dirname(cachedFile), path.basename(cachedFile))
}
catch (e) {
if (!removeIfInvalid) {
throw e
}
try {
await unlink(cachedFile)
}
catch (ignore) {
// ignore
}
return false
}
async function validateChecksums (validationArgs) {
console.log(`Validating checksums for files from ${validationArgs.fileSource} ` +
`against ${validationArgs.shaSumFile}.`)
const shaSumFilePath = path.join(validationArgs.fileDirectory, validationArgs.shaSumFile)
const checker = new sumchecker.ChecksumValidator(validationArgs.algorithm,
shaSumFilePath, validationArgs.checkerOpts)
await checker.validate(validationArgs.fileDirectory, validationArgs.filesToCheck)
.catch(err => {
if (err instanceof sumchecker.ChecksumMismatchError) {
console.error(`${fail} The checksum of ${err.filename} from ` +
`${validationArgs.fileSource} did not match the shasum in ` +
`${validationArgs.shaSumFile}`)
} else if (err instanceof sumchecker.ChecksumParseError) {
console.error(`${fail} The checksum file ${validationArgs.shaSumFile} ` +
`from ${validationArgs.fileSource} could not be parsed.`, err)
} else if (err instanceof sumchecker.NoChecksumFoundError) {
console.error(`${fail} The file ${err.filename} from ` +
`${validationArgs.fileSource} was not in the shasum file ` +
`${validationArgs.shaSumFile}.`)
} else {
console.error(`${fail} Error matching files from ` +
verifyChecksum (cb) {
let options = {}
if (semver.lt(this.version, '1.3.5')) {
options.defaultTextEncoding = 'binary'
}
let checker = new sumchecker.ChecksumValidator('sha256', this.cachedChecksum, options)
checker.validate(this.cache, this.filename).then(() => {
cb(null, this.cachedZip)
}, (err) => {
fs.unlink(this.cachedZip, (fsErr) => {
if (fsErr) return cb(fsErr)
cb(err)
})
})
}
}
value: function verifyChecksum(cb) {
var _this7 = this;
var options = {};
if (semver.lt(this.version, '1.3.5')) {
options.defaultTextEncoding = 'binary';
}
var checker = new sumchecker.ChecksumValidator('sha256', this.cachedChecksum, options);
checker.validate(this.cache, this.filename).then(function () {
cb(null, _this7.cachedZip);
}, function (err) {
fs.unlink(_this7.cachedZip, function (fsErr) {
if (fsErr) return cb(fsErr);
cb(err);
});
});
}
}, {