Questions tagged [bytestring]

A time and space-efficient implementation of byte vectors for Haskell.

A time and space-efficient implementation of byte vectors using packed Word8 arrays, suitable for high performance use, both in terms of large data quantities, or high speed requirements. Byte vectors are encoded as strict Word8 arrays of bytes, and lazy lists of strict chunks, held in a ForeignPtr, and can be passed between C and Haskell with little effort. Documentation can be found at the bytestring hackage page.

206 questions
1
vote
1 answer

Constructing RequestBodyStream from Lazy ByteString when length is known

I am trying to adapt this AWS S3 upload code to handle Lazy ByteString where length is already known (so that it is not forced to be read in its entirety in memory - it comes over the network where length is sent beforehand). It seems I have to…
Sal
  • 4,312
  • 1
  • 17
  • 26
1
vote
1 answer

How to output minimal binary using Data.Binary and Data.ByteString.Lazy?

Minimal test code (bs.hs): import qualified Data.Binary as B import qualified Data.ByteString.Lazy.Char8 as BSLC main = do BSLC.putStr $ B.encode $ Pad $ BSLC.pack "xxx" data Pad = Pad BSLC.ByteString instance B.Binary Pad where put (Pad…
uebayasi
  • 46
  • 4
1
vote
2 answers

Generic and efficient way to parse various kinds of integers from ByteStrings in Haskell

Here's what I could come up with but I don't think it's very efficient or safe: import qualified Data.ByteString.Char8 as B8 convert2Int = read . B8.unpack Is there a better way to do this? I found functions in libraries that do it for the Int…
donatello
  • 5,727
  • 6
  • 32
  • 56
1
vote
1 answer

Converting ByteString Generated by System.Entropy to Text

When I run this code, I get a decode error from Data.Text. What am I doing wrong? import Data.Text (Text, pack, unpack) import Data.Text.Encoding (decodeUtf8) import Data.ByteString (ByteString) import…
Ecognium
  • 2,046
  • 1
  • 19
  • 35
1
vote
3 answers

Increasing performance in file manipulation

I have a file which contains a matrix of numbers as following: 0 10 24 10 13 4 101 ... 6 0 52 10 4 5 0 4 ... 3 4 0 86 29 20 77 294 ... 4 1 1 0 78 100 83 199 ... 5 4 9 10 0 58 8 19 ... 6 58 60 13 68 0 148 41 ... . . . . . . What I am trying to…
abden003
  • 1,325
  • 7
  • 24
  • 48
1
vote
1 answer

What can be done to resolve this dependency issue?

I'm trying to install aeson after resetting ~/.ghc and ~/.cabal. cabal install aeson gives me the following error message: Resolving dependencies... cabal: Could not resolve dependencies: next goal: aeson (user goal) rejecting: aeson-0.9.0.1,…
user4223038
1
vote
1 answer

Haskell Convert ByteString To UTC Time

I have been trying to make a function in Haskell to take a ByteString which is a datetime and convert it to UTC time taking into account the time zone from the original encoding. I am very new to Haskell so I may be making a really basic…
Steve Severance
  • 6,611
  • 1
  • 33
  • 44
1
vote
1 answer

Converting literal Chars to Word8

The documentation for ByteString gives the following code example: breakByte :: Word8 -> ByteString -> (ByteString, ByteString) breakByte 'c' "abcd" However when I write the same I get the following error (ideone): Couldn't match expected type…
Clinton
  • 22,361
  • 15
  • 67
  • 163
1
vote
1 answer

Passing several ByteStrings to C

I have a C function that I want to expose to Haskell via FFI that takes three strings: c_fun :: CString -> CString -> CString -> IO () How can I use useAsCString from Data.ByteString to pass 3 ByteStrings from Haskell? I.e. I'm looking for a…
jarmond
  • 1,372
  • 1
  • 11
  • 19
1
vote
2 answers

How to match a ByteString with a NUL byte?

I want to split a huge (12GB), lazy ByteString with a Regexp that matches, among other things, a NUL \x00 byte. I know that it should be possible, given that I've been able to split a sample string with python: >>> from re import split >>>…
berdario
  • 1,851
  • 18
  • 29
1
vote
2 answers

Data.ByteString output not correct

I'm writing a program which would take a list of text files as arguments and outputs a file in which each row is the intercalation of tabs between the corresponding rows in the files. Assume all characters are ASCII encoded import…
haskelline
  • 1,116
  • 7
  • 15
1
vote
2 answers

Matching 8-bit characters in Haskell Text.Regex.Posix.ByteString

my Haskell application reads input as a list of ByteString and I'm using Text.Regex.Posix.ByteString.regexec to find matches. Some input has a character code 253 (it's a 1/2 symbol in one IBM PC character set) and it seems that the pattern '.'…
1
vote
2 answers

Haskell - How do you prepend a bytestring with its length in binary?

I'm in the unfortunate situation where I need to interface with a Java socket API directly in Haskell. The way Java Strings are sent over the wire is with their length is added to the beginning of the string. For example: \0\0\0\xBHello World is…
Joe Hillenbrand
  • 845
  • 9
  • 26
1
vote
2 answers

Why creating and disposing temporal ByteStrings eats up my memory in Haskell?

Here is a code which creates 1M Int numbers and put them in a list. main = do let l = [1..1000000] putStrLn $ show $ sum (foldl (\aux p -> p:aux) [] l) (I know it could be more optimal (sum in the fold) but my point is different.) And look at…
halacsy
  • 205
  • 2
  • 8
1
vote
2 answers

How to force strict evaluation of a sequence of ByteString

I have the following Haskell type definition: import Data.Sequence(Seq, length) import Data.ByteString.UTF8(ByteString) type StringSeq = Seq ByteString I have expressions of type StringSeq for which I would like to force strict evaluation with…
Giorgio
  • 5,023
  • 6
  • 41
  • 71