Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let pairs = [];
forOwn(object, (value, key) => {
if (value !== undefined && value !== null) {
pairs.push([key, value]);
}
});
if (!pairs.length) {
return EMPTY_HASH;
}
// Consistant key/value pair ordering
pairs = sortBy(pairs, pair => pair[0]);
// eslint-disable-next-line no-magic-numbers
return crc32(JSON.stringify(pairs)).toString(16);
}
async function ensureScenarioLoadedForInstance ({
bundleId,
instance,
modifications,
scenarioId,
workerVersion,
profileRequest,
updateStatus
}) {
// hash the modifications to detect any changes that have taken place
const scenarioHash = crc32(JSON.stringify(modifications))
// Maybe one day we'll check if anything relevant (the street network) has changed,
// that would be a performance win
if (scenarioHash !== instance.scenarioHash || workerVersion !== instance.workerVersion) {
debug(`scenario ${scenarioId} has changed, updating browsochrones`)
updateStatus(APPLYING_SCENARIO)
const scenarioUniqueId = `${scenarioId}-${scenarioHash}`
const request = getStaticSiteRequest({ modifications, bundleId, scenarioUniqueId, workerVersion, profileRequest })
// TODO don't duplicate these fields
const { jobId } = request
const body = {
request,
graphId: bundleId,
workerVersion,
jobId
}
return read(uri).then(content => ({
uri,
content,
readTime: Date.now(),
hash: crc32(content || '')
}));
}
private finishPacket(data: Buffer) {
data.writeUInt32LE(crc32(data), 8);
}
function getCRC(filename) {
return crc.crc32(fs.readFileSync(path.join(output.website, filename), {encoding: 'utf8'}));
}
export function generateAppId(executableLocation: string, title: string) {
//From https://github.com/Hafas/node-steam-shortcuts
let crcValue = crc.crc32(executableLocation + title);
let longValue = new long(crcValue, crcValue, true);
longValue = longValue.or(0x80000000);
longValue = longValue.shl(32);
longValue = longValue.or(0x02000000);
return longValue.toString();
}
files.forEach( file => {
const absolutePath = resolve( this.dir, file );
const buffer = readFileSync( absolutePath );
const checksum = crc32( buffer );
this.checksumByFile[ absolutePath ] = checksum;
this.fileByChecksum[ checksum ] = absolutePath;
});