Code from IPFS (Interplanetary File System) API JS API API: https://github.com/ipfs/js-ipfs-api/blob/master/src/api/add.js
'use strict'
const Wreck = require('wreck')
module.exports = (send) => {
return function add(files, opts, cb) {
if (typeof(opts) === 'function' && cb === undefined) {
cb = opts
opts = {}
}
if (typeof files === 'string' && files.startsWith('http')) {
return Wreck.request('GET', files, null, (err, res) => {
if (err) return cb(err)
send('add', null, opts, res, cb)
})
}
return send('add', null, opts, files, cb)
}
}
The described function is the function add()used to transfer data to IPFS.
First, I will explain what I understand: the function add()takes three arguments - if there is no object options(the user skipped it) and it was replaced by the function: the user tries to execute the callback function instead - change the callback to opts; cb = opts.
Secondly, if the cited file is a text file &&begins with http- it is obviously located remotely, and we need to extract it using Wreck.
, (send) =>? return function add...? send('add', null, opts, res, cb) return send('add', null, opts, res, cb)? (cb)? , .