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

Why isn't ByteString converted automatically to FilePath?

I'm passing a (strict) ByteString to something expecting a System.IO.FilePath, which is declared as type FilePath = String. I'm also using {-# LANGUAGE OverloadedStrings #-}. I've had conversions in some places happen automatically, but here it does…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
4
votes
1 answer

Simplest way to remove BOM from Haskell ByteString

I have LazyByteString which possibly starts with BOM. What is the easiest and preferable efficient way to remove BOM from this ByteString?
Shersh
  • 9,019
  • 3
  • 33
  • 61
4
votes
2 answers

Get a `Char` from a `ByteString`

Is there a way to get the first UTF-8 Char in a ByteString in O(1) time? I'm looking for something like headUtf8 :: ByteString -> Char tailUtf8 :: ByteString -> ByteString I'm not yet constrained to use strict or lazy ByteString, but I'd prefer…
Alec
  • 31,829
  • 7
  • 67
  • 114
4
votes
2 answers

Folding over [Word8] and ByteString with same function?

It turns out that there is no instance of Foldable available for ByteString. I'd like to write a function that uses foldl' on either [Word8] or ByteString but I can't. Since a ByteString is, data-wise, the same as [Word8], it seems that I should be…
rityzmon
  • 1,945
  • 16
  • 26
4
votes
1 answer

Ptr Word8 to ByteString

I have an FFI call returning some data bytes (not a CString). Currently, I am using something like the following: import qualified Data.ByteString as BS BS.pack <$> mapM (peekElem ptr) [0 .. n - 1] Is there a more efficient approach to this? …
Tim
  • 2,708
  • 1
  • 18
  • 32
4
votes
4 answers

Haskell Bytestring to Float Array

Hi have binaries of float data (single-precision 32-bit IEEE) that I would like to work on. How can I best load this for further use, ideally as (IOArray Int Float). bytesToFloats :: ByteString -> [Float] bytesToFloatArray :: ByteString -> IOArray…
Fabian Barkhau
  • 1,349
  • 2
  • 12
  • 31
4
votes
1 answer

Performance of reading string to Int in Haskell ( Bytestring vs [Char])

Just doing some simple benchmark on Bytestring and String. The code load a files of 10,000,000 lines, each an integer; and then convert each of the strings into the integer. Turns out the Prelude.read is much slower than ByteString.readInt. I am…
Causality
  • 1,123
  • 1
  • 16
  • 28
4
votes
2 answers

ByteString to lazy Text and vice versa

I got problems with turning ByteString's into Text and vice versa. Here's the code: {-# LANGUAGE OverloadedStrings #-} import Web.Scotty import Web.ClientSession import Data.Text.Lazy (Text, toStrict, fromStrict) import Data.Text.Lazy.Encoding…
klrr
  • 113
  • 1
  • 7
4
votes
2 answers

Matching bytestrings in Parsec

I am currently trying to use the Full CSV Parser presented in Real World Haskell. In order to I tried to modify the code to use ByteString instead of String, but there is a string combinator which just works with String. Is there a Parsec combinator…
4
votes
2 answers

Split ByteString on a ByteString (instead of a Word8 or Char)

I know I already have the Haskell Data.ByteString.Lazy function to split a CSV on a single character, such as: split :: Word8 -> ByteString -> [ByteString] But I want to split on a multi-character ByteString (like splitting on a String instead of a…
Daniel Quinlan
  • 2,639
  • 1
  • 20
  • 23
4
votes
2 answers

Converting Data.Time.UTCTime to / from ByteString

Let's say I need to do write/read of a Data.Time.UTCTime in "%Y-%m-%d %H:%M:%S" format many many times to/from a file. It seems to me that, using Data.Time.formatTime or Data.Time.parseTime to convert UTCTime to/from String and then…
shih
  • 41
  • 2
3
votes
1 answer

Haskell broken pipe error when working with streams

I'm trying to build a player using streams. The main idea is to have a thread running a player that reads from bytes that come from another thread that downloads youtube audio concurrently. The code works for a while and the content is streamed…
3
votes
1 answer

Efficient Conversion of Bytestring to [Word16]

I am attempting to do a plain conversion from a bytestring to a list of Word16s. The implementation below using Data.Binary.Get works, though it is a performance bottleneck in the code. This is understandable as IO is always going to be slow, but I…
Dylan B.
  • 73
  • 6
3
votes
0 answers

Haskell profiler sees too little memory use

I'm trying to debug a program that uses too much memory. I've got the profiling running and use the run time options -s -p -h -xt. Then I use hp2ps to plot the resulting .hp file: However the actual memory usage is somewhere around 650 Mb (the…
jorgen
  • 3,425
  • 4
  • 31
  • 53
3
votes
1 answer

How can I map a binary network packet structure to Haskell standard data types (records)?

I want to implement a binary protocol (RFC3588, Diameter) with pure Haskell. I need to know is there any better way (Than e.g. Data.Binary...) to read/write data from/to ByteStrings. I like mapping a Haskell record to ByteString, as like what is…
Kamyar
  • 2,494
  • 2
  • 22
  • 33