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

How can I get Ptr of a ByteString?

Is there a way to extract underlying direct pointer to memory off the ByteString object? My current approach is incorrect, compiler says. getPtr :: ByteString -> Ptr Word8 getPtr (PS ptr _ _) = ptr
danbst
  • 3,363
  • 18
  • 38
7
votes
2 answers

Haskell: Does ghci show "Chunk .. Empty"?

Learn You a Haskell has a code example like this: ghci> B.pack [99,97,110] Chunk "can" Empty (B stands for Data.ByteString.Lazy) But my ghci does not show Chunk and Empty data constructors. > B.pack [99,97,110] "can" Did Haskell developers…
Tengu
  • 1,014
  • 7
  • 14
7
votes
2 answers

Is there a parametric version of lazy `ByteString`?

My understanding is that ByteStrings are just lists of vectors of Word8s. This packaging gives better memory and speed performance on binary streams. Similarly, the Text type boosts performance on Char streams. But what if I have Int streams, or…
Mike Izbicki
  • 6,286
  • 1
  • 23
  • 53
7
votes
1 answer

Bytestring linking in ghc

Consider the following simple code: import Crypto.Hash.SHA1 (hashlazy) import qualified Data.ByteString as BS main = return () I installed cabal install --global bytestring and then I obtain (on a newly installed Ubuntu 12.04 machine using ghc…
Cartesius00
  • 23,584
  • 43
  • 124
  • 195
7
votes
2 answers

How to parse a 7GB file, with Data.ByteString?

I have to parse a file, and indeed a have to read it first, here is my program : import qualified Data.ByteString.Char8 as B import System.Environment main = do args <- getArgs let path = args !! 0 content <- B.readFile path let…
Fopa Léon Constantin
  • 11,863
  • 8
  • 48
  • 82
6
votes
3 answers

Converting 64-bit Double to ByteString efficiently

I wrote a function to convert 64-bit Double to ByteString (architecture/type safety is not really an issue - let us assume for now that the Double is 64-bit Word). While the function below works well, I am wondering if there is a faster way to…
Sal
  • 4,312
  • 1
  • 17
  • 26
6
votes
1 answer

What makes a Bytestring "lazy"?

I am learning Haskell but having some difficulty understanding how exactly lazy ByteStrings work. Hackage says that "Lazy ByteStrings use a lazy list of strict chunks which makes it suitable for I/O streaming tasks". In contrast, a strict list is…
lantejoula
  • 171
  • 5
6
votes
1 answer

findSubstrings and breakSubstring in Data.ByteString

In the source of Data/ByteString.hs it says that the function findSubstrings has been deprecated in favor of breakSubstring. However I think the findSubstrings which was implemented using the KMP algorithm is much more efficient than the algorithm…
sob7y
  • 61
  • 1
6
votes
2 answers

IO over big files in haskell: Performance issue

I'm trying to work over big files using Haskell. I'd like to browse an input file byte after byte, and to generate an output byte after byte. Of course I need the IO to be buffered with blocks of reasonable size (a few KB). I can't do it, and I need…
Joel
  • 3,427
  • 5
  • 38
  • 60
6
votes
1 answer

Haskell, Aeson - no instance for (ToJSON ByteString)

So happy making it this far, encountered a new hurdle: Got this code made to be encoded to JSON. However no matter when type I use as an instance, the compiler complains. Now I am obviously doing something wrong, but it is exactly what is in the…
Madderote
  • 1,107
  • 10
  • 19
6
votes
2 answers

What is the type parameter in the bytestring builder internals for?

The core datatypes of Data.ByteString.Builder are newtype Builder = Builder (forall r. BuildStep r -> BuildStep r) type BuildStep a = BufferRange -> IO (BuildSignal a) data BuildSignal a = Done {-# UNPACK #-} !(Ptr Word8) a | BufferFull …
sjakobi
  • 3,546
  • 1
  • 25
  • 43
6
votes
1 answer

Difference between Data.ByteString and Data.ByteString.Char8

I read that Char8 only supports ASCII characters and will be dangerous to use if you are using other Unicode characters {-# LANGUAGE OverloadedStrings #-} --import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC import…
laiboonh
  • 1,377
  • 1
  • 9
  • 19
6
votes
1 answer

How can I convert from a ByteString to a positive Integer

I am trying to generate large random prime numbers (1024 bit-ish) so I need a way to generate large positive random numbers. I began with System.Random but want to move to Crypto.Random from the crypto-api package. The Crypto.Random only produces…
user668074
  • 1,111
  • 10
  • 16
6
votes
0 answers

Parse command-line arguments as ByteString

Is there a cross-platform way to parse program arguments into a list of ByteString (instead of a list of String, as in System.Environment.getArgs)? I am aware of System.Posix.Env.ByteString.getArgs from the unix package, but I would like to be able…
user2384183
6
votes
2 answers

Reading in a binary file in haskell

How could I write a function with a definition something like... readBinaryFile :: Filename -> IO Data.ByteString I've got the functional parts of Haskell down, but the type system and monads still make my head hurt. Can someone write and explain…
Clark Gaebel
  • 17,280
  • 20
  • 66
  • 93
1 2
3
13 14