Last active
January 9, 2021 20:22
-
-
Save themaxdavitt/9a5cc0910089f8af3de5b8f185811880 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Max Davitt - https://max.davitt.me | |
// Released under CC0 1.0 Universal | |
// https://creativecommons.org/publicdomain/zero/1.0/ | |
const { createHash } = require('crypto'); | |
const readFile = require('util').promisify(require('fs').readFile); | |
(async () => { | |
if (process.argv.length < 3) { | |
console.error('usage: node har_md5sum.js test.har ...'); | |
} else { | |
console.log( | |
( | |
await Promise.all( | |
process.argv.slice(2).map(async (path) => [path, await readFile(path, 'utf8')]) | |
) | |
) | |
.map(([path, json]) => [path, JSON.parse(json)]) | |
.map(([path, har]) => `# ${path}\n${ | |
har.log.entries | |
.map((entry) => { | |
const { url } = entry.request; | |
const { content } = entry.response; | |
const hash = createHash('md5'); | |
hash.update(content.text, content.encoding || 'utf8'); | |
return `${url}\t${hash.digest('hex')}`; | |
}) | |
.join('\n')}` | |
) | |
.join('\n') | |
); | |
} | |
})().catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment