bytestring-progress 1.0.2 → 1.0.2.1
raw patch · 2 files changed
+35/−1 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Example.hs +32/−0
- bytestring-progress.cabal +3/−1
+ Example.hs view
@@ -0,0 +1,32 @@+import Network.HTTP (simpleHTTP, Request, mkRequest)+import Network.HTTP.Base (Response(..), RequestMethod(..))+import Network.HTTP.Headers (HeaderName(..), findHeader)+import Network.Stream (ConnError)+import Network.URI (parseURI)+import Data.ByteString.Lazy.Progress (trackProgressString)+import qualified Data.ByteString.Lazy as BS+import System.IO (openBinaryFile, hClose, IOMode(..))+import System.Environment (getArgs)++downloadFile :: String -> FilePath -> IO ()+downloadFile url path = do+ fhndl <- openBinaryFile path WriteMode+ http <- simpleHTTP dbReq+ case http of+ Left x -> fail $ "Couldn't download file: " ++ show x+ Right resp -> do+ let size = read `fmap` findHeader HdrContentLength resp+ putStrLn $ "Total size is " ++ show size ++ " bytes."+ track <- trackProgressString formatStr size handler+ track (rspBody resp) >>= BS.hPut fhndl+ hClose fhndl+ putStrLn "Done!"+ where+ dbReq = mkRequest GET link+ Just link = parseURI url+ formatStr = "\r Downloading file ... %p (%R, estimated done in %T)"+ handler = putStr++main :: IO ()+main = do+ downloadFile "http://ftp.ndlug.nd.edu/pub/fedora/linux/releases/16/Fedora/x86_64/iso/Fedora-16-x86_64-netinst.iso" "foo.iso"
bytestring-progress.cabal view
@@ -1,5 +1,5 @@ Name: bytestring-progress-Version: 1.0.2+Version: 1.0.2.1 Build-Type: Simple Cabal-Version: >= 1.6 License: BSD3@@ -15,6 +15,8 @@ consumed. Typically, this could be to report some measure of progress to a waiting user, but it could also be to perform some form of testing on input / consumption code.++data-files: Example.hs Library Build-Depends: base >= 4.0 && < 5.0,