本文整理匯總了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))