[Haskell-cafe] How do I use ByteString?
Don Stewart
dons at galois.com
Mon Apr 5 21:51:23 EDT 2010
gue.schmidt:
> Hi all,
>
> I've never found an easy way to deal with ByteStrings.
>
> I'm using the RSA library and it en- and decodes
> Data.ByteString.Lazy.ByteString.
>
> I initially start with Strings, ie. [Char], but there is no function to
> convert the 2 back and forth. There is however a function which takes
> [Word8] to BytesString and back.
>
> It all wouldn't be so confusing if there weren't several versions of
> ByteString in several modules to choose from. And a number of libraries
> requiring different types of ByteString.
>
> I am sure the designers of the bytestring package had good reason for
> this design, is there also a webpage which explains which one to use and
> under what circumstances?
As a general rule you should never convert between String and
bytestring. You can read bytestrings from files, or write literals using
"pack" or the -XOverloadedStrings extension
Converting between lazy and strict bytestrings is a representation
change, and changes complexity - so be aware of what you're doing. You
can do this via fromChunks or concat . toChunks.
-- Don
More information about the Haskell-Cafe
mailing list