Haskell: Reading ByteString

How to convert ByteString representation of an integer to ... ok integer? Is there a special reading function for ByteStrings or do I need to unzip first than using regular reading?

Thank.

+5
source share
2 answers

You can use readInteitherreadInteger of Data.ByteString.Char8. If you want to read some other data types, you need to write your own parser; the best option is probably attoparsec , which is a library for writing fast partners ByteStringand Textsimilar to Parsec.

+4
source

In addition to great suggestions, you can also use Data.Binary.Get to read integers of a fixed length.

ghci> :m +Data.Binary.Get
ghci> :t runGet getWord64le
ByteString -> Word64
+2
source

All Articles