How to use the webtorrent-fixtures.numbers function in webtorrent-fixtures

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 / 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 / webtorrent / test / node / basic.js View on Github external
test('client.seed: filesystem path to folder with multiple files, string', function (t) {
  t.plan(7)

  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.seed(fixtures.numbers.contentPath, { announce: [] }, function (torrent) {
    t.equal(client.torrents.length, 1)
    t.equal(torrent.infoHash, fixtures.numbers.parsedTorrent.infoHash)
    t.equal(torrent.magnetURI, fixtures.numbers.magnetURI)

    const downloaded = torrent.files.map(file => ({
      length: file.length,
      downloaded: file.downloaded
    }))

    t.deepEqual(downloaded, [
      { length: 1, downloaded: 1 },
      { length: 2, downloaded: 2 },
      { length: 3, downloaded: 3 }
    ], 'expected downloaded to be calculated correctly')

    client.remove(torrent, function (err) { t.error(err, 'torrent destroyed') })
github webtorrent / parse-torrent / test / basic.js View on Github external
test('parse multiple file torrent', t => {
  const parsed = parseTorrent(fixtures.numbers.torrent)
  t.equal(parsed.infoHash, fixtures.numbers.parsedTorrent.infoHash)
  t.equal(parsed.name, fixtures.numbers.parsedTorrent.name)
  t.deepEquals(parsed.files, fixtures.numbers.parsedTorrent.files)
  t.deepEquals(parsed.announce, fixtures.numbers.parsedTorrent.announce)
  t.end()
})
github webtorrent / parse-torrent / test / basic.js View on Github external
test('parse multiple file torrent', t => {
  const parsed = parseTorrent(fixtures.numbers.torrent)
  t.equal(parsed.infoHash, fixtures.numbers.parsedTorrent.infoHash)
  t.equal(parsed.name, fixtures.numbers.parsedTorrent.name)
  t.deepEquals(parsed.files, fixtures.numbers.parsedTorrent.files)
  t.deepEquals(parsed.announce, fixtures.numbers.parsedTorrent.announce)
  t.end()
})
github webtorrent / webtorrent / test / rarity-map.js View on Github external
test('Rarity map usage', function (t) {
  t.plan(16)

  var numPieces = 4
  var torrentId = Object.assign({}, fixtures.numbers.parsedTorrent, {
    pieces: Array(numPieces)
  })
  var client = {
    listening: true,
    peerId: randombytes(20).toString('hex'),
    torrentPort: 6889,
    dht: false,
    tracker: false,
    _remove: function () {}
  }
  var opts = {}
  var torrent = new Torrent(torrentId, client, opts)
  torrent.on('metadata', function () {
    torrent._onWire(new Wire())
    torrent._onWire(new Wire())
github webtorrent / create-torrent / test / stream.js View on Github external
const files = fs.readdirSync(fixtures.numbers.contentPath).map(file => {
    const stream = fs.createReadStream(`${fixtures.numbers.contentPath}/${file}`)
    stream.name = file
    return stream
  })
github webtorrent / webtorrent / test / node / basic.js View on Github external
client.seed(fixtures.numbers.contentPath, { announce: [] }, function (torrent) {
    t.equal(client.torrents.length, 1)
    t.equal(torrent.infoHash, fixtures.numbers.parsedTorrent.infoHash)
    t.equal(torrent.magnetURI, fixtures.numbers.magnetURI)

    const downloaded = torrent.files.map(file => ({
      length: file.length,
      downloaded: file.downloaded
    }))

    t.deepEqual(downloaded, [
      { length: 1, downloaded: 1 },
      { length: 2, downloaded: 2 },
      { length: 3, downloaded: 3 }
    ], 'expected downloaded to be calculated correctly')

    client.remove(torrent, function (err) { t.error(err, 'torrent destroyed') })
    t.equal(client.torrents.length, 0)

    client.destroy(function (err) { t.error(err, 'client destroyed') })