Actually, i&#39;m wondering how to do exception handling and resource cleanup in iteratee, e.g. your `writer` iteratee, i found it difficult, because iteratee is designed to let enumerator manage resources. <br><br><div class="gmail_quote">

On Sat, Jul 23, 2011 at 2:41 AM, Eric Rasmussen <span dir="ltr">&lt;<a href="mailto:ericrasmussen@gmail.com">ericrasmussen@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Hi everyone,<br>
<br>
A friend of mine recently asked if I knew of a utility to split a<br>
large file (4gb in his case) into arbitrarily-sized files on Windows.<br>
Although there are a number of file-splitting utilities, the catch was<br>
it couldn&#39;t break in the middle of a line. When the standard &quot;why<br>
don&#39;t you use Linux?&quot; response proved unhelpful, I took this as an<br>
opportunity to write my first program using the enumerator package.<br>
<br>
If anyone has time, I&#39;m really interested in knowing if there&#39;s a<br>
better way to take the incoming stream and output it directly to a<br>
file. The basic steps I&#39;m taking are:<br>
<br>
1) Data.Enumerator.Binary.take -- grabs the user-specified number of<br>
bytes, then (because it returns a lazy ByteString) I use<br>
Data.ByteString.Lazy.hPut to output the chunk<br>
2) Data.Enumerator.Binary.head -- after using take for the big chunk,<br>
it inspects and outputs individual characters and stops after it<br>
outputs the next newline character<br>
3) I close the handle that steps 1&amp;2 used to output the data and then<br>
repeat 1&amp;2 with the next handle (an infinite lazy list of filepaths<br>
like part1.csv, part2.csv, and so on)<br>
<br>
The full code is pasted here: <a href="http://hpaste.org/49366" target="_blank">http://hpaste.org/49366</a>, and while I&#39;d<br>
like to get any other feedback on how to make it better, I want to<br>
note that I&#39;m not planning to release this as a utility so I wouldn&#39;t<br>
want anyone to spend extra time performing a full code review.<br>
<br>
Thanks!<br>
Eric<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><a href="http://www.yi-programmer.com/blog/">http://www.yi-programmer.com/blog/</a><br>