[Haskell-cafe] Parsec and binary files

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Thu Jun 8 11:53:07 EDT 2006

On Thu, 2006-06-08 at 11:49 -0300, Atila Romero wrote:
> Im trying to use parsec to split a file, using the null character as a 
> separator.
> Works fine with very small files but fails if they are a little bit larger.
> I guess parsec is trying to parse everthing first and print the results 
> last.

I think so.

> Am I doing something wrong or parsec is just not the right tool to the job?

Right. In this case I would use lazy byte strings.

module main where

import qualified Data.ByteString.Lazy as B

main = do
  input <- B.getContents
  let emails = B.split 0 input

This lazily reads and splits into chunks using a 0 byte as separator.

However this needs a fairly recent version of the 'fps' package. (In ghc
6.6 Data.ByteString and Data.ByteString.Lazy will be provided in the
base package.)


More information about the Haskell-Cafe mailing list