Permalink
Browse files

fixes #3

  • Loading branch information...
1 parent c03f91e commit ede7ba00a20e26006fd76e23ca3e0e45897594cf @nikmikov nikmikov committed May 6, 2012
Showing with 11 additions and 4 deletions.
  1. +2 −1 Combinatorrent.cabal
  2. +9 −3 src/Protocol/BCode.hs
View
@@ -27,7 +27,7 @@ data-files: AUTHORS, README.md
flag debug
description: Enable debug support
- default: False
+ default: True
flag threaded
description: Build with threaded runtime
@@ -85,6 +85,7 @@ executable Combinatorrent
test-framework,
test-framework-hunit,
test-framework-quickcheck2,
+ text,
time
ghc-options: -Wall -fno-warn-orphans -funbox-strict-fields
View
@@ -44,6 +44,9 @@ import Control.Applicative hiding (many)
import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString as B
+import qualified Data.Text as T
+import qualified Data.Text.Encoding as T
+
import Data.Char
import Data.List
@@ -97,6 +100,9 @@ toBS = B.pack . map toW8
fromBS :: B.ByteString -> String
fromBS = map fromW8 . B.unpack
+fromUtf8BS :: B.ByteString -> String
+fromUtf8BS = T.unpack . T.decodeUtf8
+
instance Serialize BCode where
put (BInt i) = wrap 'i' 'e' $ putShow i
@@ -295,13 +301,13 @@ numberPieces :: BCode -> Maybe Int
numberPieces = fmap length . infoPieces
infoFiles :: BCode -> Maybe [([String], Integer)] -- ^[(filePath, fileLength)]
-infoFiles bc = let mbFpath = fromBS `fmap` infoName bc
+infoFiles bc = let mbFpath = fromUtf8BS `fmap` infoName bc
mbLength = infoLength bc
mbFiles = do BArray fileList <- searchInfo "files" bc
return $ do fileDict@(BDict _) <- fileList
let Just (BInt l) = search [toPS "length"] fileDict
Just (BArray pth) = search [toPS "path"] fileDict
- pth' = map (\(BString s) -> fromBS s) pth
+ pth' = map (\(BString s) -> fromUtf8BS s) pth
return (pth', l)
in case (mbFpath, mbLength, mbFiles) of
(Just fpath, _, Just files) ->
@@ -347,7 +353,7 @@ pp bc =
BArray arr -> text "[" <+> (cat $ intersperse comma al) <+> text "]"
where al = map pp arr
BDict mp -> text "{" <+> cat (intersperse comma mpl) <+> text "}"
- where mpl = map (\(s, bc') -> text (fromBS s) <+> text "->" <+> pp bc') $ M.toList mp
+ where mpl = map (\(s, bc') -> text (fromUtf8BS s) <+> text "->" <+> pp bc') $ M.toList mp
prettyPrint :: BCode -> String
prettyPrint = render . pp

0 comments on commit ede7ba0

Please sign in to comment.