aboutsummaryrefslogtreecommitdiffhomepage
path: root/Data/Text/Pipes.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Data/Text/Pipes.hs')
-rw-r--r--Data/Text/Pipes.hs13
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 ()
205stdin = fromHandle IO.stdin 205stdin = 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.
209fromHandle :: MonadIO m => IO.Handle -> Producer' Text m () 210fromHandle :: MonadIO m => IO.Handle -> Producer' Text m ()
210fromHandle h = go where 211fromHandle 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
220TEXT-PIPES
221==========
222TEXT PIPES, SOMEHOW TO BE FUSED WITH `PIPES-TEXT`.
223...
224>>>
225-}
226
216readFile :: (MonadSafe m, Base m ~ IO) => FilePath -> Producer' Text m () 227readFile :: (MonadSafe m, Base m ~ IO) => FilePath -> Producer' Text m ()
217readFile file = Safe.withFile file IO.ReadMode fromHandle 228readFile file = Safe.withFile file IO.ReadMode fromHandle
218{-# INLINABLE readFile #-} 229{-# INLINABLE readFile #-}