summaryrefslogtreecommitdiff
path: root/src/Data/Torrent
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/Torrent')
-rw-r--r--src/Data/Torrent/Progress.hs24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/Data/Torrent/Progress.hs b/src/Data/Torrent/Progress.hs
index d0aa75c6..1a4a68e2 100644
--- a/src/Data/Torrent/Progress.hs
+++ b/src/Data/Torrent/Progress.hs
@@ -12,6 +12,7 @@
12-- 12--
13{-# LANGUAGE TemplateHaskell #-} 13{-# LANGUAGE TemplateHaskell #-}
14{-# LANGUAGE ViewPatterns #-} 14{-# LANGUAGE ViewPatterns #-}
15{-# OPTIONS -fno-warn-orphans #-}
15module Data.Torrent.Progress 16module Data.Torrent.Progress
16 ( -- * Progress 17 ( -- * Progress
17 Progress (..) 18 Progress (..)
@@ -36,13 +37,15 @@ module Data.Torrent.Progress
36import Control.Applicative 37import Control.Applicative
37import Control.Lens hiding ((%=)) 38import Control.Lens hiding ((%=))
38import Data.Aeson.TH 39import Data.Aeson.TH
40import Data.ByteString.Lazy.Builder as BS
41import Data.ByteString.Lazy.Builder.ASCII as BS
39import Data.Default 42import Data.Default
40import Data.List as L 43import Data.List as L
41import Data.Monoid 44import Data.Monoid
42import Data.Serialize as S 45import Data.Serialize as S
43import Data.Ratio 46import Data.Ratio
44import Data.URLEncoded
45import Data.Word 47import Data.Word
48import Network.HTTP.Types.QueryLike
46import Text.PrettyPrint as PP 49import Text.PrettyPrint as PP
47import Text.PrettyPrint.Class 50import Text.PrettyPrint.Class
48 51
@@ -89,18 +92,19 @@ instance Monoid Progress where
89 } 92 }
90 {-# INLINE mappend #-} 93 {-# INLINE mappend #-}
91 94
92instance URLShow Word64 where 95instance QueryValueLike Builder where
93 urlShow = show 96 toQueryValue = toQueryValue . BS.toLazyByteString
94 {-# INLINE urlShow #-} 97
98instance QueryValueLike Word64 where
99 toQueryValue = toQueryValue . BS.word64Dec
95 100
96-- | HTTP Tracker protocol compatible encoding. 101-- | HTTP Tracker protocol compatible encoding.
97instance URLEncode Progress where 102instance QueryLike Progress where
98 urlEncode Progress {..} = mconcat 103 toQuery Progress {..} =
99 [ s "uploaded" %= _uploaded 104 [ ("uploaded" , toQueryValue _uploaded)
100 , s "left" %= _left 105 , ("left" , toQueryValue _left)
101 , s "downloaded" %= _downloaded 106 , ("downloaded", toQueryValue _downloaded)
102 ] 107 ]
103 where s :: String -> String; s = id; {-# INLINE s #-}
104 108
105instance Pretty Progress where 109instance Pretty Progress where
106 pretty Progress {..} = 110 pretty Progress {..} =