0

I have a producer pipe and I have used the print pipe. I would like to write the output to a file. If I use Control.Data.sinkFile, like

test2file = runPipe $ CB.sinkFile "testOutput" <+< traverseTree fn3 

I get a type error:

Couldn't match expected type `Pipe
                                b0 void-0.5.8:Data.Void.Void m0 r0'
            with actual type `Data.Conduit.Internal.Pipe
                                l0 Data.ByteString.Internal.ByteString o0 r1 m1 r1'
In the return type of a call of `sinkFile'
In the first argument of `(<+<)', namely `sinkFile "testOutput"'

How do I convert sinkFile to a pipe which can be composed. is there a Strict vs. Lazy question?

4

1 回答 1

2

解决方案很简单,编写一个 fileSink 函数,该函数附加到一个文件

fileSink = forever $ do 
inp <- await
liftIO $ appendFile "testOutput" ('\n' : show inp )
return () 

使用文件句柄可能更有效,更实用的是,将文件名作为参数传递。使用管道真的很容易!

于 2012-09-29T14:27:52.443 回答