npm install webtorrent
Чтобы установить программу командной строки webtorrent, выполните: npm install webtorrent-cli -g
Загрузка файла:
var WebTorrent = require('webtorrent')
var client = new WebTorrent()
var magnetURI = '...'
client.add(magnetURI, function (torrent) {
// Got torrent metadata!
console.log('Client is downloading:', torrent.infoHash)
torrent.files.forEach(function (file) {
// Display the file by appending it to the DOM.Supports video, audio, images, and more. Specify a container element (CSS selector or reference to DOM node).
file.appendTo('body')
})
})
Заполнение файла
var dragDrop = require('drag-drop')
var WebTorrent = require('webtorrent')
var client = new WebTorrent()
// When user drops files on the browser, create a new torrent and start seeding it!
dragDrop('body', function (files) {
client.seed(files, function (torrent) {
console.log('Client is seeding:', torrent.infoHash)
})
})