Yet another weakly defined bug report

Peter Thiemann thiemann@informatik.uni-freiburg.de
13 Feb 2003 09:45:35 -0800


Hi Ketil,

I know your problem all too well. If you are sure that you need all of
the file's content, then you should read it all from the start. I've
found this little function handy and I'm using it all over the place:

readFileStrictly :: FilePath -> IO String
readFileStrictly filePath =
  do h <- openFile filePath ReadMode
     contents <- hGetContents h
     hClose (g contents h)
     return contents
  where
    g [] h = h
    g (_:rest) h = g rest h

Also, 
     hClose (length contents `seq` h)
would work.

If this is too strict for your purposes (eg, if you don't know that
you need this file's content at all), then you can still wrap it
into unsafePerformIO.

Hope this helps
-Peter