UNPKG

universal-fs

Version:

Allows a client or server to access the file system in the current codebase or a different one.

18 lines (13 loc) 392 B
import {isBrowser, isNode} from "browser-or-node"; const pollyfillBuffer = async () => { let BufferPolyfill; if (isBrowser) { BufferPolyfill = (await import("buffer/")).Buffer; } else if (isNode) { BufferPolyfill = Buffer; } else { throw new Error("Failed to pollyfill Buffer. Unsupported environment"); } return BufferPolyfill; }; export default pollyfillBuffer;