本文整理汇总了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();
});
});
开发者ID:HawkHouseIntegration,项目名称:DefinitelyTyped,代码行数:51,代码来源:webtorrent-tests.ts
示例2:
return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res))
开发者ID:jiang263,项目名称:PeerTube,代码行数:1,代码来源:miscs.ts
注:本文中的webtorrent.add函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论