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

How can I convert a (StorableArray (Int, Int) Word8) into a lazy ByteString?

I am trying to load a PNG file, get the uncompressed RGBA bytes, then send them to the gzip or zlib packages. The pngload package returns image data as a (StorableArray (Int, Int) Word8), and the compression packages take lazy ByteStrings.…
Keith Holman
  • 497
  • 5
  • 7
6
votes
1 answer

OverloadedStrings for chars

The hackage documentation for ByteString contains this example: split :: Word8 -> ByteString -> [ByteString] split '\n' "a\nb\nd\ne" == ["a","b","d","e"] It's as if '\n' is converted to a Word8, but LANGUAGE OverloadedStrings seems only to work on…
Clinton
  • 22,361
  • 15
  • 67
  • 163
6
votes
1 answer

parsec combinators and Text/ByteString

The Haskell parser/combinator Parsec supports input streams from Data.ByteString and Data.Text. Are there any plans to add more support for these types in future releases? The combinators (many, sepby, string...) seem to be designed around lists,…
Mike Menzel
  • 583
  • 2
  • 12
6
votes
3 answers

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?…
user12163
6
votes
1 answer

Efficient logging of string data in Haskell's ST Monad

I have a Haskell program that generates ~280M of logging text data during a run inside the ST monad. This is where virtually all memory consumption goes (with logging disabled the program allocates a grand total of 3MB real memory). Problem is, I…
NBFGRTW
  • 459
  • 3
  • 11
5
votes
1 answer

Size of Chunk in Data.ByteString.Lazy

Module Data.ByteString.Lazy contain own implementation of ByteString type: data ByteString = Empty | Chunk !S.ByteString ByteString And there are following phrase about size of chunk: The default chunk size is 64k, which should be good in most …
Dmitry Bespalov
  • 5,179
  • 3
  • 26
  • 33
5
votes
3 answers

Problem with bit swapping in Haskell

As part of a school project I'm implementing some crypthographic algorithms in Haskell. As you probably know this involves quite a lot of low level bit fiddling. Now I am stuck on one particular sub routine which causes me a headache. The routine,…
hakoja
  • 896
  • 7
  • 16
5
votes
1 answer

How to store recursive datatype with Data.Binary

Data.Binary is great. There is just one question I have. Let's imagine I've got a datatype like this: import Data.Binary data Ref = Ref { refName :: String, refRefs :: [(String, Ref)] } instance Binary Ref where put a = put (refName a)…
Lanbo
  • 15,118
  • 16
  • 70
  • 147
5
votes
1 answer

Why can't I return a ByteString from a Handler in Yesod?

I'm trying to return a ByteString from my Handler function in Yesod: getHomeR :: Handler ByteString getHomeR = return "foo" but I'm getting this error: /Users/maximiliantagher/Documents/Mercury/hs/mercury-web-backend/src/Application.hs:48:1:…
MaxGabriel
  • 7,617
  • 4
  • 35
  • 82
5
votes
1 answer

Replace newlines in ByteString

I'd like a function that takes a ByteString and replaces newlines \n and \n\r with commas, but can't think of a nice way to do it. import qualified Data.ByteString as BS import Data.Char (ord) import Data.Word (Word8) endlWord8 = fromIntegral $…
jorgen
  • 3,425
  • 4
  • 31
  • 53
5
votes
2 answers

IOUArray to ByteSring, as quickly as possible

I need to mutate elements in a fixed size array of Word8 very quickly. For this purpose I am using an IOUArray. I need to send this array over a websocket connection. The function sendBinaryData from the websockets package requires a ByteString. I…
felixgb
  • 153
  • 1
  • 7
5
votes
3 answers

Efficient streaming and manipulation of a byte stream in Haskell

While writing a deserialiser for a large ()* encoded binary file I got stuck with the various Haskell produce-transform-consume libraries. So far I'm aware of four streaming libraries: Data.Conduit: Widely used, has very careful…
mcmayer
  • 1,931
  • 12
  • 22
5
votes
2 answers

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…
Kevin
  • 283
  • 2
  • 5
5
votes
1 answer

No heap profiling data for module Data.ByteString

I was trying to generate heap memory profile for following naive Haskell code that copies a file: import System.Environment import System.IO import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as LB naiveCopy :: String ->…
6bb79df9
  • 147
  • 8
5
votes
2 answers

String -> ByteString and reverse

In my Haskell Program I need to work with Strings and ByteStrings: import Data.ByteString.Lazy as BS (ByteString) import Data.ByteString.Char8 as C8 (pack) import Data.Char (chr) stringToBS :: String -> ByteString stringToBS str…
Martin Fischer
  • 697
  • 1
  • 6
  • 27