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
5
votes
1 answer

chunksOf analog for ByteString?

I need to split bytestring into list of bytestrings diving first one by 100 characters. For lists, I can use chunksOf but not for ByteString. Is there some proper way to do this?
Filip van Hoft
  • 301
  • 1
  • 7
5
votes
2 answers

How to create two ByteStrings calling this external library API?

I'm currently writing bindings to a cryptographic library that exposes a function for generating keypairs: const size_t PUBLICKEYBYTES = 32; const size_t SECRETKEYBYTES = 32; int random_keypair(unsigned char pk[PUBLICKEYBYTES], …
dnaq
  • 2,104
  • 1
  • 14
  • 24
5
votes
1 answer

Why ByteString is not Vector Word8?

Seems like strict ByteString is structuraly same as Vector Word8. Why ByteString is not deprecated in favor of Vector? Are there performance examples when ByteString is faster than Vector Byte8?
danbst
  • 3,363
  • 18
  • 38
5
votes
2 answers

ByteString concatMap performance

I have a 37MB bin file I am trying to convert to a ppm sequence. It works fine, and I'm trying to use this as an exercise to learn some profiling and more about lazy bytestrings in Haskell. My program seems to bomb at the concatMap, which is used to…
sudochop
  • 53
  • 5
5
votes
2 answers

In Haskell, how can I replace an ASCII character sub-string in a ByteString?

In Haskell, how can I replace an ASCII character sub-string in a ByteString? How can I use function replace in Data.ByteString.Search using character strings as arguments? Are there other ways to perform sub-string replacement in a ByteString? …
Derek Mahar
  • 27,608
  • 43
  • 124
  • 174
5
votes
4 answers

Frequency of characters

I am trying to find frequency of characters in file using Haskell. I want to be able to handle files ~500MB size. What I've tried till now It does the job but is a bit slow as it parses the file 256 times calculateFrequency :: L.ByteString ->…
Ravi Upadhyay
  • 314
  • 1
  • 3
  • 16
5
votes
2 answers

Faster ByteString construction tips

I am new to Haskell, and I've stuck with efficiency issues.. Task is: Build CSV file from 4GB text file where columns have constant size column sizes are known, for example [col1: 4 chars wide, col2: 2 chars wide, etc... file can only contain…
5
votes
2 answers

ByteString assumes ISO-8859-1?

The documentation for Data.ByteString.hGetContents says As with hGet, the string representation in the file is assumed to be ISO-8859-1. Why should it have to "assume" anything about the "string representation in the file"? The data is not…
massysett
  • 1,100
  • 6
  • 13
5
votes
3 answers

How to convert a ByteString to an Int and dealing with endianness?

I need to read a binary format in Haskell. The format is fairly simple: four octets indicating the length of the data, followed by the data. The four octets represent an integer in network byte-order. How can I convert a ByteString of four bytes to…
user142019
5
votes
1 answer

Are there monadic/applicative map (i.e. traverse/mapM) functions over ByteString or Text?

There are standard (pure) map functions for ByteString and Text: map :: (Word8 -> Word8) -> ByteString -> ByteString map :: (Char -> Char) -> Text -> Text but I'm missing their monadic/applicative counterparts: traverse :: (Applicative f) => (Word8…
Petr
  • 62,528
  • 13
  • 153
  • 317
4
votes
1 answer

Writing storable instance for CString with O(1) function to get total byte length

I am trying to write a storable vector instance for CString (null-terminated C chars in my case). The storable instance will store the pointers that the CString is (Ptr CChar). So, length of the vector is the number of CString pointers. Now, the…
Sal
  • 4,312
  • 1
  • 17
  • 26
4
votes
1 answer

Most efficient way to determine if "length" of ByteString Builder >= N?

Given a Builder what's the most efficient way to determine if the serialized/reified data is greater than, say, 1kB? . My best plan currently is using toLazyByteStringWith with a 1kB initial chunk size, and inspect just the first chunk to see if…
jberryman
  • 16,334
  • 5
  • 42
  • 83
4
votes
1 answer

how do I read a 24 bit int of out of a haskell bytestring?

I'm trying to parse a binary format (PES) using Haskell: import qualified Data.ByteString.Lazy as BL import Data.Word import Data.Word.Word24 import qualified Data.ByteString.Lazy.Char8 as L8 data Stitch = MyCoord Int Int deriving (Eq, Show) data…
nont
  • 9,322
  • 7
  • 62
  • 82
4
votes
0 answers

Efficient lazy ByteString generation, using random ByteString as an example

There seems to be some impediment to efficient lazy ByteString generation by recursion. To demonstrate this, the chosen task is to make a lazy random ByteString. (Random number generation is just a reasonably meaningful operation, i.e. a placeholder…
mcmayer
  • 1,931
  • 12
  • 22
4
votes
0 answers

Byte array (byte string) data structure with persistent, pure interface

I'm looking for a data structure that stores bytes, allows constant-time pure indexing, and presents a pure, persistent interface for updating. Basically, I'm looking for Idris's equivalent of Haskell (strict) bytestrings. Data.ByteArray provides a…
Cactus
  • 27,075
  • 9
  • 69
  • 149