@@ -26,6 +26,7 @@ module Data.Text.IO
26 , appendFile
26 , appendFile
27 -- * Operations on handles
27 -- * Operations on handles
28 , hGetContents
28 , hGetContents
29 , hGetLine
30 , hGetLine
31 , hPutStrLn
32 , hPutStrLn
@@ -97,6 +98,22 @@ writeFile p = withFile p WriteMode . flip hPutStr
97appendFile :: FilePath -> Text -> IO ()
98appendFile :: FilePath -> Text -> IO ()
98appendFile p = withFile p AppendMode . flip hPutStr
99appendFile p = withFile p AppendMode . flip hPutStr
101+-- | Read a single chunk of strict text from a 'Handle'.
102+hGetChunk :: Handle -> IO Text
103+hGetChunk h = wantReadableHandle "hGetChunk" h readSingleChunk
105+ readSingleChunk hh@Handle__{..} = do
108+ buf <- readIORef haCharBuffer
109+ return $ if isEmptyBuffer buf
111+ else T.singleton '\r'
112+ | otherwise = throwIO (augmentIOError e "hGetChunk" h)
113+ buf <- readIORef haCharBuffer
114+ t <- readChunk hh buf `catch` catchError
100-- | Read the remaining contents of a 'Handle' as a string. The
117-- | Read the remaining contents of a 'Handle' as a string. The
101-- 'Handle' is closed once the contents have been read, or if an
118-- 'Handle' is closed once the contents have been read, or if an
102-- exception is thrown.
119-- exception is thrown.