Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2015-01-11 06:59:53 +0300
committerFeross Aboukhadijeh <feross@feross.org>2015-01-11 06:59:53 +0300
commitac3584b31b68a21b27a9ba40f96249debbf6fcad (patch)
treecbc492958e8b5518adb6d794143cc0cc5fe9469c /bin
parent198ac76f6c476cee4b5d1774f9b667777a7d9b54 (diff)
command line: add `create` command
Fixes #232
Diffstat (limited to 'bin')
-rwxr-xr-xbin/cmd.js27
1 files changed, 24 insertions, 3 deletions
diff --git a/bin/cmd.js b/bin/cmd.js
index cf202bb..36a5e6e 100755
--- a/bin/cmd.js
+++ b/bin/cmd.js
@@ -1,5 +1,6 @@
#!/usr/bin/env node
+var createTorrent = require('create-torrent')
var clivas = require('clivas')
var cp = require('child_process')
var fs = require('fs')
@@ -66,6 +67,9 @@ if (command === 'help' || argv.help) {
} else if (command === 'info') {
torrentId = argv._[1]
info(torrentId)
+} else if (command === 'create') {
+ var input = argv._[1]
+ create(input)
} else if (command === 'download') {
torrentId = argv._[1]
download(torrentId)
@@ -102,8 +106,9 @@ function help () {
webtorrent download "magnet:?xt=urn:btih:..." --vlc
Available commands:
- download download a torrent
- info show info for a .torrent file or magnet uri
+ download Download a torrent
+ create Create a .torrent file
+ info Show info for a .torrent file or magnet uri
Specify torrents as one of the following:
* magnet uri
@@ -151,7 +156,23 @@ function info (torrentId) {
delete parsedTorrent.info
delete parsedTorrent.infoBuffer
- console.log(JSON.stringify(parsedTorrent, undefined, 2))
+ var output = JSON.stringify(parsedTorrent, undefined, 2)
+ if (argv.out) {
+ fs.writeFileSync(argv.out, output)
+ } else {
+ process.stdout.write(output)
+ }
+}
+
+function create (input) {
+ createTorrent(input, function (err, torrent) {
+ if (err) return errorAndExit(err)
+ if (argv.out) {
+ fs.writeFileSync(argv.out, torrent)
+ } else {
+ process.stdout.write(torrent)
+ }
+ })
}
function download (torrentId) {