UNPKG

ipfs-only-hash

Version:

Just enough code to calculate the IPFS hash for some data

23 lines (17 loc) 540 B
const { importer } = require('ipfs-unixfs-importer') const block = { get: async cid => { throw new Error(`unexpected block API get for ${cid}`) }, put: async () => { throw new Error('unexpected block API put') } } exports.of = async (content, options) => { options = options || {} options.onlyHash = true if (typeof content === 'string') { content = new TextEncoder().encode(content) } let lastCid for await (const { cid } of importer([{ content }], block, options)) { lastCid = cid } return `${lastCid}` }