UNPKG

identify-media

Version:

Analyse file path and content to make search criteria for media APIs

42 lines 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeHash = void 0; const initBlock = (size) => { let temp = size; const longs = []; for (let i = 0; i < 8; i++) { longs[i] = temp & 255; temp = temp >> 8; } return longs; }; const processChunk = (chunk, init) => { return chunk.split('').reduce((result, current, index) => { const idx = (index + 8) % 8; return result.slice(0, idx).concat(result[idx] + current.charCodeAt(0)).concat(result.slice(idx + 1)); }, init); }; const longsToBin = (longs) => { return longs.reduce((result, current) => { const sum = current + result.overflow; const overflow = sum >> 8; return { normalized: result.normalized.concat(sum & 255), overflow }; }, { normalized: [], overflow: 0 }).normalized; }; const bin2hex = (longs) => { const hexString = '0123456789abcdef'; return longsToBin(longs).reverse().reduce((result, current) => { return result + hexString.charAt(current >> 4 & 15) + hexString.charAt(current & 15); }, ''); }; const makeHash = (size, firstChunk, secondChunk) => { return firstChunk .then((chunk) => processChunk(chunk, initBlock(size))) .then((longs) => secondChunk.then((chunk) => processChunk(chunk, longs))) .then(bin2hex); }; exports.makeHash = makeHash; //# sourceMappingURL=makeHash.js.map