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
2
votes
2 answers

Datatype to ByteString

I have a newtype I'd like to save in a file, something like this: type Index = (Int, Int) newtype Board a = Board { unboard :: Array Index a } So basically an Array. But maybe I want to add some other data one day like this: data BoardWithInfo a =…
Lanbo
  • 15,118
  • 16
  • 70
  • 147
2
votes
3 answers

Trying to pass a random string to SHA in Haskell

I'm trying to pass a random string (which happens to be a number) "4176730.5" to SHA in Haskell to get a larger random string like "2d711642b726b04401627ca9fbac32f5c8530fb1903cc4db02258717921a4881". I have this code to generate a random number and…
Adjam
  • 598
  • 1
  • 8
  • 22
2
votes
1 answer

How to read a 5-byte thing into a `Word64` using `binary`?

Is it possible to read a 5-byte segment of data into a Word64 using the binary package, leaving the three higher-order bits empty? Or must I use a ByteString?
xuq01
  • 588
  • 4
  • 17
2
votes
0 answers

Haskell FFI: Correct way to pass in and return ByteStrings

Setup Suppose you have a typical C API where some struct is allocated, then initialised (memory allocated, handles created, etc.), then worked upon (transformed, queried, etc.) using various functions, and finally freed again. I.e. the standard…
mcmayer
  • 1,931
  • 12
  • 22
2
votes
2 answers

Streaming bytestring as WAI HTTP server response body

I have a value body :: BS.ByteString (ResourceT IO) (), from a function based on BS.readFile. I want to stream that value as the response body from a Wai Application. There's a helper, streamingResponse that takes a value of the type Stream (Of…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
2
votes
1 answer

Conduit that checks file header

I'd like to use Conduit in a setting where I read a binary file, check that it has the correct header, and then work on the remaining data in the file. Trying to write a conduit that checks the header and then streams the rest of the data on to the…
jorgen
  • 3,425
  • 4
  • 31
  • 53
2
votes
1 answer

Split lazy bytestring with another bytestring

How can I split a lazy bytestring with another bytestring (e.g. "\r\n")? I'm looking for a function like the following: BSL.ByteString -> BSL.ByteString -> [BSL.ByteString] I know about breakSubstring but that function is only available for strict…
2
votes
5 answers

Efficient output of numbers

I want to print a list of integrals separated with spaces to stdout. The list generation is fast, so I tried to solve this problem with the sequence [1..200000]. In C, I can implement it like this: #include "stdio.h" int main() { int i; for(i =…
Christian
  • 4,042
  • 4
  • 26
  • 28
2
votes
1 answer

Reading samples, from a file, into an array

I've written a program that analyzes sample data that is contained an a file. Currently, my program reads the samples into a list and I perform the further analyzation/processing on the list of samples ([Float]). I'm not quite happy with the…
user7420876
2
votes
2 answers

Bit-wise operations on ByteString

In Haskell, it seems that bit-wise operations are typically handled via the Data.Bits module and the Bits class. I'd like to perform bit-manipulations on ByteStrings of any length (eg set, clear, shift, masks...) but I cannot find an instance of…
Janthelme
  • 989
  • 10
  • 23
2
votes
1 answer

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…
Fopa Léon Constantin
  • 11,863
  • 8
  • 48
  • 82
2
votes
0 answers

How to efficiently "poke" a ByteString value of a given length at a Ptr?

"Peeking", to read a pointer ptr to a new ByteString, is straightforward: BS.packCStringLen (ptr, size) But the poke operation (writing a ByteString into a given memory location) isn't that obvious. We have useAsCStringLen :: ByteString ->…
Petr
  • 62,528
  • 13
  • 153
  • 317
2
votes
2 answers

replace double backslash with single backslash in haskell

I want to replace "\\" from a bytestring sequence (Data.ByteString) with "\", but due to the internal escaping of "\" it won't work. Consider following example: The original bytestring: "\159\DEL*\150\222/\129vr\205\241=mA\192\184" After storing…
auermich
  • 130
  • 10
2
votes
1 answer

Updating a value in Data.ByteString

The C language provides a very handy way of updating the nth element of an array: array[n] = new_value. My understanding of the Data.ByteString type is that it provides a very similar functionality to a C array of uint8_t - access via index ::…
Daniel Lovasko
  • 471
  • 2
  • 10
2
votes
0 answers

ByteString transformation

I'm trying to write a simple function to transform ByteStrings with given ratio. Quantity of xored bits depends on the length and ratio. rr <- randomRIO (0, BL.length bs) let howMuch = floor $ (ratio args) * (fromIntegral rr) transformIndexes <-…