UNPKG

ipfs-unixfs-importer

Version:

JavaScript implementation of the UnixFs importer used by IPFS

24 lines 949 B
import errCode from 'err-code'; import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; export const defaultChunkValidator = () => { return async function* validateChunks(source) { for await (const content of source) { if (content.length === undefined) { throw errCode(new Error('Content was invalid'), 'ERR_INVALID_CONTENT'); } if (typeof content === 'string' || content instanceof String) { yield uint8ArrayFromString(content.toString()); } else if (Array.isArray(content)) { yield Uint8Array.from(content); } else if (content instanceof Uint8Array) { yield content; } else { throw errCode(new Error('Content was invalid'), 'ERR_INVALID_CONTENT'); } } }; }; //# sourceMappingURL=validate-chunks.js.map