diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-07 15:17:17 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-08 09:30:31 +0200 |
commit | 3e17515e2996b79e23f569c296051a91af3fcbe4 (patch) | |
tree | d1c06c394a9f4b1d8646625612c2d5d3e02e9191 /server/helpers/webtorrent.ts | |
parent | 187501f8b8e334f043ae1e9af3c9d4f45ea0e6c1 (diff) | |
download | PeerTube-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.ts | 9 |
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' | |||
2 | import { generateVideoTmpPath } from './utils' | 2 | import { generateVideoTmpPath } from './utils' |
3 | import * as WebTorrent from 'webtorrent' | 3 | import * as WebTorrent from 'webtorrent' |
4 | import { createWriteStream } from 'fs' | 4 | import { createWriteStream } from 'fs' |
5 | import { Instance as ParseTorrent } from 'parse-torrent' | ||
6 | import { CONFIG } from '../initializers' | 5 | import { CONFIG } from '../initializers' |
7 | import { join } from 'path' | 6 | import { 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 | }) |