diff options
Diffstat (limited to 'lib/util.js')
-rw-r--r-- | lib/util.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/util.js b/lib/util.js index 5546716..dbefa14 100644 --- a/lib/util.js +++ b/lib/util.js @@ -62,6 +62,10 @@ u.hyperwrap = function (fn) { } } +u.toLink = function (link) { + return typeof link === 'string' ? {link: link} : link +} + u.linkDest = function (link) { return typeof link === 'string' ? link : link && link.link || link } @@ -114,3 +118,19 @@ u.isMsgEncrypted = function (msg) { var c = msg && msg.value.content return typeof c === 'string' } + +u.pullConcat = function (cb) { + return pull.collect(function (err, bufs) { + if (err) return cb(err) + cb(null, Buffer.concat(bufs)) + }) +} + +u.customError = function (name) { + return function (message) { + var error = new Error(message) + error.name = name + error.stack = error.stack.replace(/^ at .*\n/m, '') + return error + } +} |