MCPcopy
hub / github.com/Kong/insomnia / createIntegrity

Function createIntegrity

packages/insomnia/bin/yarn-standalone.js:29120–29152  ·  view source on GitHub ↗
(opts)

Source from the content-addressed store, hash-verified

29118
29119module.exports.create = createIntegrity
29120function createIntegrity (opts) {
29121 opts = opts || {}
29122 const algorithms = opts.algorithms || ['sha512']
29123 const optString = opts.options && opts.options.length
29124 ? `?${opts.options.join('?')}`
29125 : ''
29126
29127 const hashes = algorithms.map(crypto.createHash)
29128
29129 return {
29130 update: function (chunk, enc) {
29131 hashes.forEach(h => h.update(chunk, enc))
29132 return this
29133 },
29134 digest: function (enc) {
29135 const integrity = algorithms.reduce((acc, algo) => {
29136 const digest = hashes.shift().digest('base64')
29137 const hash = new Hash(
29138 `${algo}-${digest}${optString}`,
29139 opts
29140 )
29141 if (hash.algorithm && hash.digest) {
29142 const algo = hash.algorithm
29143 if (!acc[algo]) { acc[algo] = [] }
29144 acc[algo].push(hash)
29145 }
29146 return acc
29147 }, new Integrity())
29148
29149 return integrity
29150 }
29151 }
29152}
29153
29154const NODE_HASHES = new Set(crypto.getHashes())
29155

Callers

nothing calls this directly

Calls 6

mapMethod · 0.80
shiftMethod · 0.80
updateMethod · 0.65
forEachMethod · 0.45
reduceMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected