How to use webtorrent-fixtures - 10 common examples

To help you get started, we’ve selected a few webtorrent-fixtures examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webtorrent / webtorrent / test / node / download-metadata.js View on Github external
test('Download metadata magnet URI with unsupported protocol in xs parameter', function (t) {
  t.plan(1)

  var client = new WebTorrent({ dht: false, tracker: false })

  client.on('error', function (err) { t.fail(err) })
  client.on('warning', function (err) { t.fail(err) })

  client.add(fixtures.leaves.magnetURI + '&xs=' + encodeURIComponent('invalidurl:example'), { store: MemoryChunkStore })

  setTimeout(function () {
    // no crash by now
    client.destroy(function (err) { t.error(err, 'client destroyed') })
  }, 100)
})
github webtorrent / webtorrent / test / client-add-duplicate-trackers.js View on Github external
test('client.add: duplicate trackers (including in .torrent file), multiple torrents', function (t) {
  t.plan(5)

  // Re-use this object, in case webtorrent is changing it
  var opts = {
    announce: ['wss://example.com', 'wss://example.com', 'wss://example.com']
  }

  // Include the duplicate trackers in the .torrent files
  var parsedTorrentLeaves = Object.assign({}, fixtures.leaves.parsedTorrent)
  parsedTorrentLeaves.announce = ['wss://example.com', 'wss://example.com', 'wss://example.com']

  var parsedTorrentAlice = Object.assign({}, fixtures.alice.parsedTorrent)
  parsedTorrentAlice.announce = ['wss://example.com', 'wss://example.com', 'wss://example.com']

  var client = new WebTorrent({ dht: false, tracker: false })

  client.on('error', function (err) { t.fail(err) })
  client.on('warning', function (err) { t.fail(err) })

  var torrent1 = client.add(parsedTorrentLeaves, opts)

  torrent1.on('ready', function () {
    t.equal(torrent1.magnetURI, fixtures.leaves.magnetURI + '&tr=' + encodeURIComponent('wss://example.com'))

    var torrent2 = client.add(parsedTorrentAlice, opts)

    torrent2.on('ready', function () {
      t.equal(torrent2.magnetURI, fixtures.alice.magnetURI + '&tr=' + encodeURIComponent('wss://example.com'))
github webtorrent / create-torrent / test / fs.js View on Github external
test('create multi file torrent with array of paths', t => {
  t.plan(20)

  const number10Path = path.join(fixtures.lotsOfNumbers.contentPath, 'big numbers', '10.txt')
  const number11Path = path.join(fixtures.lotsOfNumbers.contentPath, 'big numbers', '11.txt')
  const numbersPath = fixtures.numbers.contentPath

  const input = [number10Path, number11Path, numbersPath]

  const startTime = Date.now()
  createTorrent(input, {
    name: 'multi',

    // force piece length to 32KB so info-hash will
    // match what transmission generated, since we use
    // a different algo for picking piece length
    pieceLength: 32768,

    private: false // also force `private: false` to match transmission

  }, (err, torrent) => {
    t.error(err)
github webtorrent / create-torrent / test / mixed.js View on Github external
test('create multi file torrent with array of mixed types', t => {
  t.plan(20)

  const number11Path = path.join(fixtures.lotsOfNumbers.contentPath, 'big numbers', '11.txt')
  const number10Path = path.join(fixtures.lotsOfNumbers.contentPath, 'big numbers', '10.txt')
  const numbersPath = fixtures.numbers.contentPath

  const stream = fs.createReadStream(number10Path)
  stream.name = '10.txt'

  // Note: Order should be preserved
  const input = [number11Path, stream, numbersPath]

  const startTime = Date.now()
  createTorrent(input, {
    name: 'multi',

    // force piece length to 32KB so info-hash will
    // match what transmission generated, since we use
    // a different algo for picking piece length
    pieceLength: 32768,
github webtorrent / create-torrent / test / stream.js View on Github external
test('create multi file torrent with streams', t => {
  t.plan(16)

  const files = fs.readdirSync(fixtures.numbers.contentPath).map(file => {
    const stream = fs.createReadStream(`${fixtures.numbers.contentPath}/${file}`)
    stream.name = file
    return stream
  })

  const startTime = Date.now()
  createTorrent(files, {
    // force piece length to 32KB so info-hash will
    // match what transmission generated, since we use
    // a different algo for picking piece length
    pieceLength: 32768,

    private: false, // also force `private: false` to match transmission

    name: 'numbers'
github webtorrent / create-torrent / test / fs.js View on Github external
test('create multi file torrent', t => {
  t.plan(16)

  const startTime = Date.now()
  createTorrent(fixtures.numbers.contentPath, {
    // force piece length to 32KB so info-hash will
    // match what transmission generated, since we use
    // a different algo for picking piece length
    pieceLength: 32768,

    private: false // also force `private: false` to match transmission

  }, (err, torrent) => {
    t.error(err)

    const parsedTorrent = parseTorrent(torrent)

    t.equals(parsedTorrent.name, 'numbers')

    t.notOk(parsedTorrent.private)
github webtorrent / ut_metadata / test / fetch.js View on Github external
test('fetch()', t => {
  t.plan(3)

  const wire1 = new Protocol()
  const wire2 = new Protocol()
  wire1.pipe(wire2).pipe(wire1)

  wire1.use(utMetadata(leavesMetadata.torrent)) // wire1 already has metadata
  wire2.use(utMetadata()) // wire2 does not

  wire2.ut_metadata.fetch()

  wire2.ut_metadata.on('metadata', _metadata => {
    // got metadata!
    t.equal(
      _metadata.toString('hex'),
      bencode.encode({
        info: bencode.decode(leavesMetadata.torrent).info
      }).toString('hex')
    )
  })

  wire2.on('handshake', (infoHash, peerId, extensions) => {
    wire2.handshake(leavesMetadata.parsedTorrent.infoHash, id2)
github webtorrent / create-torrent / test / fs.js View on Github external
test('create multi file torrent with nested directories', t => {
  t.plan(21)

  const startTime = Date.now()
  createTorrent(fixtures.lotsOfNumbers.contentPath, {
    // force piece length to 32KB so info-hash will
    // match what transmission generated, since we use
    // a different algo for picking piece length
    pieceLength: 32768,

    private: false // also force `private: false` to match transmission

  }, (err, torrent) => {
    t.error(err)

    const parsedTorrent = parseTorrent(torrent)

    t.equals(parsedTorrent.name, 'lots-of-numbers')

    t.notOk(parsedTorrent.private)
github webtorrent / create-torrent / test / fs.js View on Github external
test('create multi file torrent with array of paths', t => {
  t.plan(20)

  const number10Path = path.join(fixtures.lotsOfNumbers.contentPath, 'big numbers', '10.txt')
  const number11Path = path.join(fixtures.lotsOfNumbers.contentPath, 'big numbers', '11.txt')
  const numbersPath = fixtures.numbers.contentPath

  const input = [number10Path, number11Path, numbersPath]

  const startTime = Date.now()
  createTorrent(input, {
    name: 'multi',

    // force piece length to 32KB so info-hash will
    // match what transmission generated, since we use
    // a different algo for picking piece length
    pieceLength: 32768,

    private: false // also force `private: false` to match transmission
github webtorrent / create-torrent / test / mixed.js View on Github external
test('create multi file torrent with array of mixed types', t => {
  t.plan(20)

  const number11Path = path.join(fixtures.lotsOfNumbers.contentPath, 'big numbers', '11.txt')
  const number10Path = path.join(fixtures.lotsOfNumbers.contentPath, 'big numbers', '10.txt')
  const numbersPath = fixtures.numbers.contentPath

  const stream = fs.createReadStream(number10Path)
  stream.name = '10.txt'

  // Note: Order should be preserved
  const input = [number11Path, stream, numbersPath]

  const startTime = Date.now()
  createTorrent(input, {
    name: 'multi',

    // force piece length to 32KB so info-hash will
    // match what transmission generated, since we use
    // a different algo for picking piece length
    pieceLength: 32768,