bytestring

Many types of String (ByteString)

Hi, I wish to compress my application's network traffic. According to the (latest?) "Haskell Popularity Rankings", zlib seems to be a pretty popular solution. zlib's interface uses ByteStrings: compress :: ByteString -> ByteString decompress :: ByteString -> ByteString I am using regular Strings, which are also the data types used b...

Convert Byte String to Int in Scheme

I have code like this to convert hex into byte string (define (word->bin s) (let ((n (string->number s))) (bytes (bitwise-and (arithmetic-shift n -24) #xFF) (bitwise-and (arithmetic-shift n -16) #xFF) (bitwise-and (arithmetic-shift n -8) #xFF) (bitwise-and n #xFF)))) (word->bin "#x10000002") I'm thinking of a similar...

Using Haskell's Parsec to parse a ByteString

I've managed to use Parsec to parse a String, but cannot manage to do the same with a ByteString. How can I make Parsec work with ByteStrings without manually converting them to Strings? I get the feeling this isn't hard to accomplish. Am I wrong? (I'm new to Haskell. ^^) Thanks! ...

How to convert a Integer to a ByteString in Haskell

Hi, We'd like to serialize data in a specific binary format. We use Data.ByteStrings internally. So, the question is: How to convert the different data types we use to a ByteString. For String we have no problem, we can use encodeLazyByteString UTF8 "string". But we'd also like to convert Integers to ByteStrings (big-endian). Does any...

Haskell ByteString / Data.Binary.Get question

Attempting to use Data.Binary.Get and ByteString and not understanding what's happening. My code is below: getSegmentParams :: Get (Int, L.ByteString) getSegmentParams = do seglen <- liftM fromIntegral getWord16be params <- getByteString (seglen - 2) return (seglen, params) I get the following error against the third item...

In Haskell, will calling length on a Lazy ByteString force the entire string into memory?

I am reading a large data stream using lazy bytestrings, and want to know if at least X more bytes is available while parsing it. That is, I want to know if the bytestring is at least X bytes long. Will calling length on it result in the entire stream getting loaded, hence defeating the purpose of using the lazy bytestring? If yes, the...

Serializing Python bytestrings to JSON, preserving ordinal character values

I have some binary data produced as base-256 bytestrings in Python (2.x). I need to read these into JavaScript, preserving the ordinal value of each byte (char) in the string. If you'll allow me to mix languages, I want to encode a string s in Python such that ord(s[i]) == s.charCodeAt(i) after I've read it back into JavaScript. The c...

What is the best way to convert String to ByteString

What is the best way to convert a String to a ByteString in Haskell? My gut reaction to the problem is import qualified Data.ByteString as B import Data.Char (ord) packStr = B.pack . map (fromIntegral . ord) But this doesn't seem satisfactory. ...

parser for Data.ByteString.Lazy.Char8 in Haskell ?

Hi i'm facing the following problem, i have to re-write an existant code to improve his performances. the old version was using a parser defined like this : newtype Parser Char a = Parser {runParser :: [Char] -> [(a,[Char])]} to parse lines from files. but it was too slow and required a lot of memory to achieve the computation upon l...

Haskell ByteStrings - ending up with large file loaded into memory

Greetings, I'm trying to understand why I'm seeing the entire file loaded into memory with the following program, yet if you comment out the line below "(***)" then the program runs in constant (about 1.5M) space. EDIT: The file is about 660MB, the field in column 26 is a date string like '2009-10-01', and there are one million lines....

Haskell Bytestrings: How to pattern match?

I'm a haskell newbie, and having a bit of trouble figuring out how to pattern match a ByteString. The [Char] version of my function looks like: dropAB :: String -> String dropAB [] = [] dropAB (x:[]) = x:[] dropAB (x:y:xs) = if x=='a' && y=='b' then dropAB xs else x:(dropAB $ y:xs) As expec...