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

haskell reading a vector of pairs from bytestring very slow, how to make it faster?

I am trying to read a large vector of custom data type from a binary file. I tried to use the example given here. The trouble with the example code is, it uses lists and I want to use vectors. So I adapted that code as below, but it takes very long…
mntk123
  • 905
  • 6
  • 18
3
votes
1 answer

Easy switch between lazy and strict ByteString

I need to work with strict and lazy ByteStrings, because this is the requirement preset by the choice of libraries (some mix of happstack, base64, sha256, hexpat, etc.). After some dancing with "fromStrict" and similar I ended up with this: import…
Mikhail Puzanov
  • 219
  • 1
  • 7
3
votes
1 answer

Safecopy migrating from string to bytestring

I am trying to use the safecopy haskell library, but when I try to migrate a string to a bytestring, the last 4 characters are lost and 4 '\NULL' characters get prepended to the string: {-# LANGUAGE TemplateHaskell, DeriveDataTypeable, TypeFamilies…
jchmrt
  • 33
  • 2
3
votes
2 answers

Haskell HTTP client using ByteString

I'm doing some HTTP Requests and I want to get the corresponding Responses as ByteString instead of String. I'm using HTTP-4000.2.18. As far as I can tell, this is precisely what BufferType is for: to give the user freedom in how request and…
adizere
  • 224
  • 1
  • 10
3
votes
2 answers

Haskell ByteString / Data.Binary.Get question

Attempting to use Data.Binary.Get and ByteString and not understanding what's happening. My code is below: getSegmentParams :: Get (Int, L.ByteString) getSegmentParams = do seglen <- liftM fromIntegral getWord16be params <- getByteString…
me2
  • 744
  • 6
  • 13
3
votes
1 answer

Does Data.Attoparsec.ByteString use "zero copy"ing?

Take for example takeWhile. Internally it uses span. Does that mean it just references the input bytestring? Probably not, if so, is there a way to achieve this? The motivating usecase is a large (>2gb) file that I want to map into memory and…
fho
  • 6,787
  • 26
  • 71
3
votes
1 answer

ByteString expects different ByteString

This code doesn't typecheck: import Network.HTTP.Conduit import qualified Data.ByteString.Char8 as BS main :: IO () main = do resp <- simpleHttp "http://www.google.com" putStrLn $ BS.unpack resp Throws the following error: Couldn't match…
Sibi
  • 47,472
  • 16
  • 95
  • 163
3
votes
2 answers

Haskell lazy Bytestring words not lazy?

I have the following Haskell program for computing a maximum sum substring of a string of integers: {-# LANGUAGE BangPatterns #-} {-# OPTIONS_GHC -O2 #-} import Data.Functor import Data.Maybe import Data.ByteString.Lazy.Char8…
user1531083
  • 750
  • 6
  • 15
3
votes
5 answers

What is the best way to store and sort rectangular data in Haskell?

I have a handful of ASCII files containing around 17 million lines in total, and within each/most lines is a fixed 36-byte identifier. So my data is rectangular: I have a lot of rows of fixed width. Using Haskell, I want to read all the lines in,…
Neil Brown
  • 3,558
  • 1
  • 27
  • 36
3
votes
2 answers

Lazy ByteString built from Socket handle cannot be consumed and GCed lazily

I'm writing a network file transfer application. Using Lazy ByteString as a intermediate import qualified Data.ByteString.Lazy as BSL When constructing a BSL from local file, then put the BSL to a Handle of Socket: BSL.readFile filename >>=…
wuxb
  • 2,572
  • 1
  • 21
  • 30
3
votes
1 answer

Using base64-bytestring with lazy ByteStrings

Here's what I'm trying to do in Haskell: take a message in ByteString format (doesn't really matter if lazy or strict) encrypt the message with an RSA public key base64 encode the encrypted message The RSA library that I'm using handles lazy…
user519736
2
votes
1 answer

Deleting the last line of a file in Haskell

I am a beginner to Haskell and am trying to rewrite one of my shell scripts in Haskell as a test. One of the things I am trying to accomplish is removing the last line of a file and reading its value. I tried to use readFile and then writeFile, but…
2
votes
1 answer

Using SBV to show satisfiability of predicates containing byte strings in Haskell

I want to use the Data.SBV library to prove satisfiability of predicates containing byte strings of arbitrary length (from Data.ByteString). To illustrate, a predicate could be: ([0,0,1] + [255,255,255]) == [0,0,0] In order to do so, I need to…
Nico Naus
  • 21
  • 1
2
votes
1 answer

Effect of import order on ByteString type signature

I'm puzzled by GHCI's behavior around Data.ByteString and Data.ByteString.Char8. If I load a file with the following imports import qualified Data.Text as T import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC import…
planarian
  • 2,047
  • 18
  • 18
2
votes
1 answer

Why do Data.Binary instances of bytestring add the length of the bytestring as prefix

Looking at the put instances of the various ByteString types we find that the length of the bytestring is always prefixed in the binary file before writing it. For example here -…
Abhiroop Sarkar
  • 2,251
  • 1
  • 26
  • 45