How do I convert a ByteString representation of an Integer to ... well Integer? Is there a special read function for ByteStrings or do I have to unpack first than use normal read?
Thanks.
You can use readInt
or readInteger
from Data.ByteString.Char8
. If you want to read some other type of data, you'll need to write your own parser; the best choice is probably attoparsec, which is a library for writing fast ByteString
and Text
parsers, similar to Parsec.
In addition to ehird's excellent suggestions, you can also use Data.Binary.Get for reading fixed-length integers.
ghci> :m +Data.Binary.Get
ghci> :t runGet getWord64le
ByteString -> Word64
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With