-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcat.js
More file actions
38 lines (31 loc) · 828 Bytes
/
cat.js
File metadata and controls
38 lines (31 loc) · 828 Bytes
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
'use strict'
const promisify = require('promisify-es6')
const cleanCID = require('ipfs-api/src/utils/clean-cid')
const v = require('is-ipfs')
const bl = require('bl')
module.exports = (send) => {
return promisify((hash, opts, callback) => {
if (typeof opts === 'function') {
callback = opts
opts = {}
}
try {
hash = cleanCID(hash)
} catch (err) {
if (!v.ipfsPath(hash)) {
return callback(err)
}
}
const query = {
offset: opts.offset,
length: opts.length
}
send({ path: 'cat', args: hash, buffer: opts.buffer, qs: query, timeout: opts.timeout }, (err, stream) => {
if (err) { return callback(err) }
stream.pipe(bl((err, data) => {
if (err) { return callback(err) }
callback(null, data)
}))
})
})
}