From: Ramakrishnan Muthukrishnan Date: Sun, 19 Jul 2015 08:58:32 +0000 (+0530) Subject: src/Main.hs: if no input file is given, read from stdin X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/priv/frontends/index.php?a=commitdiff_plain;h=7c51ac500bf453cfdcd25c40ba7690a753b94f38;p=functorrent.git src/Main.hs: if no input file is given, read from stdin This change makes it play nicely as a Unix program that consumes streams of bytes. One possible usage is to do a 'curl' of the torrent file and pipe into the functorrent program. --- diff --git a/src/Main.hs b/src/Main.hs index 12af02e..867e962 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,8 +1,8 @@ {-# LANGUAGE OverloadedStrings #-} module Main where -import Prelude hiding (log, length, readFile) -import Data.ByteString.Char8 (ByteString, readFile, unpack) +import Prelude hiding (log, length, readFile, getContents) +import Data.ByteString.Char8 (ByteString, getContents, readFile, unpack) import System.Environment (getArgs) import System.Exit (exitSuccess) import System.Directory (doesFileExist) @@ -25,7 +25,7 @@ usage :: IO () usage = putStrLn "usage: functorrent torrent-file" parse :: [String] -> IO ByteString -parse [] = usage >> exit +parse [] = getContents parse [a] = do fileExist <- doesFileExist a if fileExist