Skip to content

Instantly share code, notes, and snippets.

@themaxdavitt
Last active January 9, 2021 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save themaxdavitt/9a5cc0910089f8af3de5b8f185811880 to your computer and use it in GitHub Desktop.
Save themaxdavitt/9a5cc0910089f8af3de5b8f185811880 to your computer and use it in GitHub Desktop.
// 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