From a24623827ffb3c715926130fc983e0b5cb7452e1 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 10 Feb 2015 12:34:34 -0400 Subject: bittorrent: Fix mojibake introduced in parsing arai2c progress output. hGetSomeString reads one byte at a time, so unicode bytes are not composed. The problem comes when outputting that to the console with hPut; that tried to apply the handle's encoding, and so we get mojibake. Instead, use ByteStrings, and only convert it to a string for parsing, not for display. Note that there are a couple of other things that use hGetSomeString, which I've left as-is for now. --- Utility/Metered.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'Utility') diff --git a/Utility/Metered.hs b/Utility/Metered.hs index 84694b26b..7d6e71cdd 100644 --- a/Utility/Metered.hs +++ b/Utility/Metered.hs @@ -1,6 +1,6 @@ {- Metered IO - - - Copyright 2012, 2013 Joey Hess + - Copyright 2012-2105 Joey Hess - - License: BSD-2-clause -} @@ -17,6 +17,7 @@ import System.IO.Unsafe import Foreign.Storable (Storable(sizeOf)) import System.Posix.Types import Data.Int +import Data.Bits.Utils {- An action that can be run repeatedly, updating it on the bytes processed. - @@ -163,12 +164,13 @@ commandMeter progressparser meterupdate cmd params = liftIO $ catchBoolIO $ p = proc cmd (toCommand params) feedprogress prev buf h = do - s <- hGetSomeString h 80 - if null s + b <- S.hGetSome h 80 + if S.null b then return True else do - putStr s + S.hPut stdout b hFlush stdout + let s = w82s (S.unpack b) let (mbytes, buf') = progressparser (buf++s) case mbytes of Nothing -> feedprogress prev buf' h -- cgit v1.2.3