<br><div class="gmail_extra">On Tue, Nov 27, 2012 at 11:28 PM, Ganesh Sittampalam <span dir="ltr"><<a href="mailto:ganesh@earth.li" target="_blank">ganesh@earth.li</a>></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>
> I think some way to use BufferCodecs without going through the<br>
> filesystem would be very useful. One other approach would be<br>
> Bytestring-backed Handles; there was talk of them in the past, but I<br>
> don't know of any actual packages for it yet. That might be a simpler<br>
> approach than manipulating BufferCodecs directly, since you could just<br>
</div>> use the functions from <a href="http://Data.Text.IO" target="_blank">Data.Text.IO</a> <<a href="http://Data.Text.IO" target="_blank">http://Data.Text.IO</a>> and all of the<br>
<div>> buffering and error recovery would get taken care of automatically.<br>
><br>
> This 2009 email from Simon Marlow references bytestring-backed handles<br>
> and has a code sample for memory-mapped files that might be helpful:<br>
> <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>
> He also mentions bytestring-backed Handles in this talk:<br>
> <a href="http://community.haskell.org/~simonmar/GHC-IO.pdf" target="_blank">http://community.haskell.org/~simonmar/GHC-IO.pdf</a><br>
> That code's probably bitrotted a little, but seems like a good place to<br>
> 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'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 -> IO ByteString<br>
<br>
but since Handle is a single type rather than a type class, that'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'd?<br></blockquote><div><br></div><div>How about something like this?</div><div><br></div><div>createFromHandle :: (Handle -> IO ()) -> 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 -> (Ptr Word8 -> IO ()) -> IO ByteString</div></div><div><br></div><div>-Judah</div></div></div>