+-- | Lazily read a given number of bytes from the handle into a
+-- 'ByteString', then close the handle.
+hGetClose :: Handle -> Int64 -> IO B.ByteString
+hGetClose h len = do
+ contents <- B.hGetContents h
+ end <- unsafeInterleaveIO (hClose h >> return B.empty)
+ return (B.append (B.take len contents) end)
+