What does the arrow function do in this code?

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)? , .

+4
1

, , - , send ; , send . , :

let addBuilder = require("add");
let add = addBuilder(senderFunction);
// This function ----^
// is `send` in the `add.js` file.
// It does the actual work of sending the command

// Then being used:
add(someFiles, someOptions, () => {
    // This is the add callback, which is `cb` in the `add.js` file
});

( , let add = require("add")(senderFunction);)

, , send, , . , , send , send; / "" send , ..

+2

All Articles