1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 19:42:24 +02:00

Add torrent tests

This commit is contained in:
Chocobozzz 2018-08-07 15:17:17 +02:00
parent 187501f8b8
commit 3e17515e29
11 changed files with 144 additions and 59 deletions

View file

@ -2,7 +2,6 @@ import { logger } from './logger'
import { generateVideoTmpPath } from './utils'
import * as WebTorrent from 'webtorrent'
import { createWriteStream } from 'fs'
import { Instance as ParseTorrent } from 'parse-torrent'
import { CONFIG } from '../initializers'
import { join } from 'path'
@ -20,10 +19,12 @@ function downloadWebTorrentVideo (target: { magnetUri: string, torrentName: stri
if (torrent.files.length !== 1) return rej(new Error('The number of files is not equal to 1 for ' + torrentId))
const file = torrent.files[ 0 ]
file.createReadStream().pipe(createWriteStream(path))
})
torrent.on('done', () => res(path))
const writeStream = createWriteStream(path)
writeStream.on('finish', () => res(path))
file.createReadStream().pipe(writeStream)
})
torrent.on('error', err => rej(err))
})