[Haskell-beginners] Reading a list of null-terminated filenames from stdin?

Michael Snoyman michael at snoyman.com
Sun Oct 11 09:45:23 UTC 2015


On Sat, Oct 10, 2015 at 9:45 PM, Dan Stromberg <strombrg at gmail.com> wrote:

>
> If I want to read a list of filenames, each terminated with a nul byte,
> from stdin (kind of like xargs -0), what's the best way to do that in
> Haskell?  Or am I swimming against the current to do anything but
> newline-termination?
>
> Google's top hit is:
>
> https://downloads.haskell.org/~ghc/7.6.1/docs/html/libraries/bytestring-0.10.0.0/Data-ByteString.html
> ...but I don't see anything about nul termination there.  I checked the
> top ~5 hits, and didn't find much.
>
> I also checked https://www.haskell.org/hoogle/?hoogle=Lines
>
> The goal is to be able to operate on filenames that contain newlines, but
> it's not that end of the world if that isn't very practical.
>
> Thanks!
>
> --
> Dan Stromberg
>
>
>
To give you an idea of how this might be done, I put together an example
using the conduit-combinators library:

https://gist.github.com/snoyberg/2a5ca79d97f483bdcfe9

This can be done in a more low-level manner by using the bytestring library
directly, which will require learning less new concepts. However, streaming
libraries like conduit and pipes are specifically designed for handling
these kinds of problems. There's a tutorial on conduit available at:

https://github.com/snoyberg/conduit#readme

Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151011/92b9db1f/attachment-0001.html>


More information about the Beginners mailing list