diff options
Diffstat (limited to 'Data/Text/Pipes.hs')
-rw-r--r-- | Data/Text/Pipes.hs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Data/Text/Pipes.hs b/Data/Text/Pipes.hs index e9b5488..f972d2d 100644 --- a/Data/Text/Pipes.hs +++ b/Data/Text/Pipes.hs | |||
@@ -205,7 +205,8 @@ stdin :: MonadIO m => Producer' Text m () | |||
205 | stdin = fromHandle IO.stdin | 205 | stdin = fromHandle IO.stdin |
206 | {-# INLINABLE stdin #-} | 206 | {-# INLINABLE stdin #-} |
207 | 207 | ||
208 | -- | Convert a 'IO.Handle' into a byte stream using a default chunk size | 208 | -- | Convert a 'IO.Handle' into a text stream using a chunk size |
209 | -- determined by the good sense of the text library. | ||
209 | fromHandle :: MonadIO m => IO.Handle -> Producer' Text m () | 210 | fromHandle :: MonadIO m => IO.Handle -> Producer' Text m () |
210 | fromHandle h = go where | 211 | fromHandle h = go where |
211 | go = do txt <- liftIO (T.hGetChunk h) | 212 | go = do txt <- liftIO (T.hGetChunk h) |
@@ -213,6 +214,16 @@ fromHandle h = go where | |||
213 | go | 214 | go |
214 | {-# INLINABLE fromHandle#-} | 215 | {-# INLINABLE fromHandle#-} |
215 | 216 | ||
217 | {-| Stream text from a file using Pipes.Safe | ||
218 | |||
219 | >>> runSafeT $ runEffect $ readFile "README.md" >-> map toUpper >-> hoist lift stdout | ||
220 | TEXT-PIPES | ||
221 | ========== | ||
222 | TEXT PIPES, SOMEHOW TO BE FUSED WITH `PIPES-TEXT`. | ||
223 | ... | ||
224 | >>> | ||
225 | -} | ||
226 | |||
216 | readFile :: (MonadSafe m, Base m ~ IO) => FilePath -> Producer' Text m () | 227 | readFile :: (MonadSafe m, Base m ~ IO) => FilePath -> Producer' Text m () |
217 | readFile file = Safe.withFile file IO.ReadMode fromHandle | 228 | readFile file = Safe.withFile file IO.ReadMode fromHandle |
218 | {-# INLINABLE readFile #-} | 229 | {-# INLINABLE readFile #-} |