aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/webtorrent.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-07 15:17:17 +0200
committerChocobozzz <me@florianbigard.com>2018-08-08 09:30:31 +0200
commit3e17515e2996b79e23f569c296051a91af3fcbe4 (patch)
treed1c06c394a9f4b1d8646625612c2d5d3e02e9191 /server/helpers/webtorrent.ts
parent187501f8b8e334f043ae1e9af3c9d4f45ea0e6c1 (diff)
downloadPeerTube-3e17515e2996b79e23f569c296051a91af3fcbe4.tar.gz
PeerTube-3e17515e2996b79e23f569c296051a91af3fcbe4.tar.zst
PeerTube-3e17515e2996b79e23f569c296051a91af3fcbe4.zip
Add torrent tests
Diffstat (limited to 'server/helpers/webtorrent.ts')
-rw-r--r--server/helpers/webtorrent.ts9
1 files changed, 5 insertions, 4 deletions
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts
index 04b3ac71b..121cd0b41 100644
--- a/server/helpers/webtorrent.ts
+++ b/server/helpers/webtorrent.ts
@@ -2,7 +2,6 @@ import { logger } from './logger'
2import { generateVideoTmpPath } from './utils' 2import { generateVideoTmpPath } from './utils'
3import * as WebTorrent from 'webtorrent' 3import * as WebTorrent from 'webtorrent'
4import { createWriteStream } from 'fs' 4import { createWriteStream } from 'fs'
5import { Instance as ParseTorrent } from 'parse-torrent'
6import { CONFIG } from '../initializers' 5import { CONFIG } from '../initializers'
7import { join } from 'path' 6import { join } from 'path'
8 7
@@ -20,10 +19,12 @@ function downloadWebTorrentVideo (target: { magnetUri: string, torrentName: stri
20 if (torrent.files.length !== 1) return rej(new Error('The number of files is not equal to 1 for ' + torrentId)) 19 if (torrent.files.length !== 1) return rej(new Error('The number of files is not equal to 1 for ' + torrentId))
21 20
22 const file = torrent.files[ 0 ] 21 const file = torrent.files[ 0 ]
23 file.createReadStream().pipe(createWriteStream(path))
24 })
25 22
26 torrent.on('done', () => res(path)) 23 const writeStream = createWriteStream(path)
24 writeStream.on('finish', () => res(path))
25
26 file.createReadStream().pipe(writeStream)
27 })
27 28
28 torrent.on('error', err => rej(err)) 29 torrent.on('error', err => rej(err))
29 }) 30 })