forked from ipfs/js-ipfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.js
39 lines (32 loc) · 979 Bytes
/
get.js
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
'use strict'
const { CID } = require('multiformats/cid')
const configure = require('./lib/configure')
const toUrlSearchParams = require('./lib/to-url-search-params')
/**
* @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions
* @typedef {import('ipfs-core-types/src/root').API<HTTPClientExtraOptions>} RootAPI
*/
module.exports = configure(api => {
/**
* @type {RootAPI["get"]}
*/
async function * get (path, options = {}) {
/** @type {Record<string, any>} */
const opts = {
arg: `${path instanceof Uint8Array ? CID.decode(path) : path}`,
...options
}
if (opts.compressionLevel) {
opts['compression-level'] = opts.compressionLevel
delete opts.compressionLevel
}
const res = await api.post('get', {
timeout: options.timeout,
signal: options.signal,
searchParams: toUrlSearchParams(opts),
headers: options.headers
})
yield * res.iterator()
}
return get
})