Created
November 26, 2018 04:57
-
-
Save carsonfarmer/6c86be544f85a2376d3221007c1c7ac9 to your computer and use it in GitHub Desktop.
Simple module to promisify ipfs initialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
'use strict' | |
import IPFS from 'ipfs' | |
const getIpfs = (opts) => { | |
opts = opts || {} | |
return new Promise(function (resolve, reject) { | |
var ipfs = new IPFS(opts) | |
var onReady = function () { | |
ipfs.removeListener('error', onError) | |
resolve(ipfs) | |
} | |
var onError = function (err) { | |
ipfs.removeListener('ready', onReady) | |
reject(err) | |
} | |
ipfs.once('ready', onReady).once('error', onError) | |
}) | |
} | |
export default getIpfs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment