-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hPutBuilder for Text's Builder type #446
Comments
I would like to have a function with which I can write a Text Builder to a For example, import System.IO
import qualified Data.Text.Lazy.IO as TL
main = withBinaryFile "test.txt" WriteMode $ \h -> TL.hPutStr h "Gebäude" With For small values like the above one could call |
I suspect that Efficient file write without forcing the entire {-# LANGUAGE OverloadedStrings #-}
import Data.ByteString.Builder (hPutBuilder)
import qualified Data.Text.Lazy.Builder as TB
import Data.Text.Lazy.Encoding (encodeUtf8Builder)
import System.IO
main = do
withBinaryFile "test.txt" WriteMode $ \h -> do
hPutBuilder h (encodeUtf8Builder $ TB.toLazyText $ TB.fromText "Gebäude") |
|
@phadej Agreed. It would be nice to have a function that goes straight from a text |
@phadej I do not see how this is any different using the lazy text hPutStr since Builder can only produce |
It seems that for this to work well a few changes need to be made
|
The A better data structure for outputting to the OS is bytestring's That's admittedly not very discoverable. I'm not sure how to improve this. |
@Lysxia You are correct with the current implementation of builder. However, in #586 I have modified Builder to be able to also be able to use pinned buffers. Pinned buffers allow the handle to use the same buffer that the builder uses thus skipping the copy from the builder buffer to the handle char buffer. This is helpful for all encodings that are not UTF-8. |
I'm not convinced adding |
I see what you mean. Thanks |
Seems like this should be closed. |
Based on discussion in #442, having a way to write a text builder directly to a handle, like bytestring's
hPutBuilder
might be a nice performance win in some situations.The text was updated successfully, but these errors were encountered: