John Goerzen wrote: > Does the attached patch fix the problem for you? Update and lseps > on your example podcast, at least, work for me with it.
All I can test is the file I attached earlier, probably they fixed their
broken podcast.
> - do c <- readFile fp
> + do h <- openBinaryFile fp ReadMode
> + c <- hGetContents h
Thinking about this some more, reading in binary could possibly fail
too. If a podcast has legitimately encoded utf-8, this will result in
c containing un-decoded raw bytes, which will then be re-encoded
wherever they're used (ie, when running curl on an url). Result
is doubly-encoded utf8.
What would work, but only with ghc 7.4, is the following:
import GHC.IO.Encoding
{- Sets a Handle to use the filesystem encoding. This causes data
- written or read from it to be encoded/decoded the same
- as ghc 7.4 does to filenames. This special encoding
- allows "arbitrary undecodable bytes to be round-tripped through it". -}
fileEncoding :: Handle -> IO ()
fileEncoding h = hSetEncoding h =<< getFileSystemEncoding
parse fp name =
do h <- openFile fp ReadMode
fileEncoding h
c <- hGetContents h
With this you still get raw bytes, but they're encoded such that
anything later done with them will not re-encode them as utf-8.
I don't know if using the filesystem encoding for non-filesystem
data is entirely kosher however.
It might be best to only read the file this way if reading it
the normal way in text mode fails.
--
see shy jo
signature.asc
Description: Digital signature

