Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | 1x 1x 1x 1x 1x 1x 1x 39x 2x 39x 4x 4x 2x 4x 39x 4x 4x 4x 4x 39x | import { caller } from 'postmsg-rpc'
import callbackify from 'callbackify'
import defer from 'pull-defer'
import PMS from 'pull-postmsg-stream'
import toStream from 'pull-stream-to-stream'
import { post } from 'prepost'
import { isBufferJson, bufferFromJson } from '../../serialization/buffer'
export default function (opts) {
const api = {
read: callbackify.variadic(
post(
caller('ipfs.files.read', opts),
bufferFromJson
)
),
readReadableStream () {
return toStream.source(api.readPullStream(...arguments))
},
readPullStream: (() => {
const readPullStream = post(
caller('ipfs.files.readPullStream', opts),
(res) => PMS.source(res.name, Object.assign({}, opts, {
post (res) {
if (isBufferJson(res.data)) {
res.data = bufferFromJson(res.data)
}
return res
}
}))
)
return (...args) => {
const deferred = defer.source()
readPullStream(...args)
.then((res) => deferred.resolve(res))
.catch((err) => deferred.abort(err))
return deferred
}
})()
}
return api
}
|