I am writing a program in which the input file is split into several files (Shamir Secret Sharing Scheme).
Here is the pipeline that I represent:
- source: use Conduit.Binary.sourceFile to read from input
- channel: takes a byte string, creates [ByteString]
- sink: Receives [ByteString] from the channel and writes each ByteString (in [ByteString]) to the corresponding file. (say, if our [ByteString] input is called bsl, then
bsl !! 0 will be written to file 0, bsl !! 1 to file 1, etc.)
I found a question about several input files here , but in their case the whole pipeline starts once for each input file, while for my program I write to several output files in the pipeline.
I also look at Conduit source code here to find out if I can implement multiSinkFile myself, but I'm a little confused as a sinkFile consumer, and more so if I try to dig deeper ... (I'm still a beginner)
So the question is, how should I implement a function like multiSinkFile, which allows you to write multiple files as part of the shell?
Any advice is welcome!
Explanation
Suppose we want to use Shamir Secret in a file containing the binary value "ABCDEF" (in 3 parts).
(So, we have our srcFile input file and our output files outFile0 , outFile1 and outFile2 )
First we read "ABC" from the file and do the processing, which will give us a list of, say, ["133", "426", "765"] . therefore, "133" will be written to outFile0 , "426" to outFile1 and "765" to outFile2 . Then we read "DEF" from srcFile , process it and write the corresponding outputs to each output file.
EDIT:
Thank you for your responses. I somehow understood what is happening with ZipSinks, etc., and I wrote a simple test program that takes the source file and simply writes it to 3 output files. Hope this helps others in the future.
{-
haskell conduit
Jacob wang
source share