本文整理汇总了TypeScript中webtorrent.add函数的典型用法代码示例。如果您正苦于以下问题:TypeScript add函数的具体用法?TypeScript add怎么用?TypeScript add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
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');
file.getBuffer(function(err, buffer) {
if (err) throw err;
console.log(buffer); // <Buffer 00 98 00 01 01 00 00 00 50 ae 07 04 01 00 00 00 0a 00 00 00 00 00 00 00 78 ae 07 04 01 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ...>
});
file.appendTo('#containerElement', function(err, elem) {
if (err) throw err; // file failed to download or display in the DOM
console.log('New DOM node with the content', elem);
});
file.getBlobURL(function(err, url) {
if (err) throw err;
var a = document.createElement('a');
// a.download = file.name
if (url) {
a.href = url;
}
a.textContent = 'Download ' + file.name;
document.body.appendChild(a);
});
});
torrent.on('done', function() {
console.log('torrent finished downloading');
torrent.files.forEach(function(file) {
// do something with file
});
});
torrent.on('download', function(chunkSize) {
console.log('chunk size: ' + chunkSize);
console.log('total downloaded: ' + torrent.downloaded);
console.log('download speed: ' + torrent.downloadSpeed);
console.log('progress: ' + torrent.progress);
console.log('======');
});
torrent.on('wire', function(wire, addr) {
console.log('connected to peer with address ' + addr);
wire.use();
});
});
示例2:
return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res))