<br><div class="gmail_extra">On Tue, Nov 27, 2012 at 11:28 PM, Ganesh Sittampalam <span dir="ltr">&lt;<a href="mailto:ganesh@earth.li" target="_blank">ganesh@earth.li</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


Hi Judah,<br>
<div><br>
On 25/11/2012 17:19, Judah Jacobson wrote:<br>
<br>
&gt; I think some way to use BufferCodecs without going through the<br>
&gt; filesystem would be very useful.  One other approach would be<br>
&gt; Bytestring-backed Handles; there was talk of them in the past, but I<br>
&gt; don&#39;t know of any actual packages for it yet.  That might be a simpler<br>
&gt; approach than manipulating BufferCodecs directly, since you could just<br>
</div>&gt; use the functions from <a href="http://Data.Text.IO" target="_blank">Data.Text.IO</a> &lt;<a href="http://Data.Text.IO" target="_blank">http://Data.Text.IO</a>&gt; and all of the<br>
<div>&gt; buffering and error recovery would get taken care of automatically.<br>
&gt;<br>
&gt; This 2009 email from Simon Marlow references bytestring-backed handles<br>
&gt; and has a code sample for memory-mapped files that might be helpful:<br>
&gt; <a href="http://www.haskell.org/pipermail/glasgow-haskell-users/2009-December/018124.html" target="_blank">http://www.haskell.org/pipermail/glasgow-haskell-users/2009-December/018124.html</a><br>
&gt; He also mentions bytestring-backed Handles in this talk:<br>
&gt; <a href="http://community.haskell.org/~simonmar/GHC-IO.pdf" target="_blank">http://community.haskell.org/~simonmar/GHC-IO.pdf</a><br>
&gt; That code&#39;s probably bitrotted a little, but seems like a good place to<br>
&gt; start.<br>
<br>
</div>Thanks for the pointers!<br>
<br>
Do you have any thoughts on what the API for creating a<br>
bytestring-backed handle should be? I&#39;m particularly thinking of the<br>
case where we are writing to the bytestring - the type could be<br>
something like<br>
<br>
    makeWritableByteStringHandle :: IO (Handle, ByteString)<br>
<br>
but then would we end up with a ByteString value that could be being<br>
mutated in parallel with being used. It might be nicer to have it in two<br>
phases, e.g.<br>
<br>
    makeWritableByteStringHandle :: IO Handle<br>
    finishByteStringHandle :: Handle -&gt; IO ByteString<br>
<br>
but since Handle is a single type rather than a type class, that&#39;s not<br>
imlpementable. Perhaps:<br>
<br>
    makeWritableByteStringHandle :: IO (Handle, IO ByteString)<br>
<br>
where the embedded IO action is only valid after the Handle has been<br>
hClose&#39;d?<br></blockquote><div><br></div><div>How about something like this?</div><div><br></div><div>createFromHandle :: (Handle -&gt; IO ()) -&gt; IO ByteString</div><div><br></div><div>That would follow the pattern of the create.* functions from Data.ByteString.Internal, e.g.</div>


<div><br></div><div><div>create :: Int -&gt; (Ptr Word8 -&gt; IO ()) -&gt; IO ByteString</div></div><div><br></div><div>-Judah</div></div></div>