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

how to improve this very slow and inefficient Haskell program to process binary files byte by byte?

I am trying to write a hexdump like program in Haskell. I wrote the following program, I am glad that it works and gives desired output but it is very slow and inefficient. It was adapted from the program given in this answer. I ran the program with…
mntk123
  • 905
  • 6
  • 18
2
votes
1 answer

Read unicode from JSON to String field using aeson

I receive a JSON data using httpLbs and read it import qualified Data.ByteString.Lazy.UTF8 as LB sendSimpleRequest :: Credentials -> IO LB.ByteString sendSimpleRequest creds = do <...> let request = applyBasicAuth user pass $ fromJust $…
Me again
  • 496
  • 2
  • 10
2
votes
1 answer

Read a list of integers lazily as a bytestring

I'm trying to find the sum of integers in a file. The code using the normal string is: main = do contents <- getContents L.putStrLn (sumFile contents) where sumFile = sum . map read. words I tried to change it to use the Data.ByteString.Lazy…
Michael Chav
  • 441
  • 5
  • 15
2
votes
1 answer

wxHaskell: convert Data.ByteString to Image

I have some raw data that represents an image as Data.ByteString. Is there a way in wxHaskell to convert it to an image/bitemap? This raw data can be an image like PNG/JPG/GIF, so it will start with byte sequences like "PNG etc". I tried to use…
Randomize
  • 8,651
  • 18
  • 78
  • 133
2
votes
2 answers

Haskell JSON Issue

been trying to get this code working but the compiler is throwing out an error? {-# LANGUAGE OverloadedStrings, DeriveGeneric #-} import Data.Aeson import Data.Text import Control.Applicative import Control.Monad import qualified…
user4201880
2
votes
1 answer

How to get a String from a Lazy.Builder?

I need to manipulate the binary encoding as '0' and '1' of simple strings given as input, using ascii 7-bits. For the encoding I have used the function Data.ByteString.Lazy.Builder.string7 :: String -> Builder However, I have not found a way to…
Stephane Rolland
  • 38,876
  • 35
  • 121
  • 169
2
votes
1 answer

haskell network io hgetline

I want to read all the data on a handle, and then block waiting for more data. listen1 stops when there is a '\n' character in the stream. listen2 works and could be made completely general by imitating the code for hGetNonBlocking. What is the…
Alex
  • 1,581
  • 2
  • 18
  • 31
2
votes
1 answer

Display full type in ghci

I have a variable of ByteString type. I want to see which package it belongs to. This could be useful for ByteString types because there are several different implementations in different packages. For instance, I have following piece of…
altern
  • 5,829
  • 5
  • 44
  • 72
2
votes
2 answers

ByteString.Lazy.Char8 (Not enough space)

This code gives : hGetBufSome: resource exhausted (Not enough space) error as soon as it's executed. import qualified Data.ByteString.Lazy.Char8 as B8 main = do (l:_) <- B8.lines `fmap` B8.getContents B8.putStrLn l I'm just trying to…
Dulguun Otgon
  • 1,925
  • 1
  • 19
  • 38
2
votes
2 answers

ByteStrings in Haskell

So i am trying to write a program that can read in a java class file as bytecode. For this i am using Data.Binary and Data.ByteStream. The problem i am having is because im pretty new to Haskell i am having trouble actually using these tools. module…
Jon
  • 31
  • 2
2
votes
1 answer

Why does decodeFile throw "not enough bytes" error?

Why does decodeFile from Data.Binary throw the error *** Exception: demandInput: not enough bytes, when using decode and readFile from Data.ByteString.Lazy works as expected? A minimal example module Testing where import Data.Binary import…
ajerneck
  • 751
  • 1
  • 7
  • 19
2
votes
2 answers

Internal data structures in Haskell (text)

So, I'm parsing some JSON into a custom data type with aeson, and I can't seem to understand why Haskell needs to have two representations of certain types in a library. In my case, this is all related to text. For example: Couldn't match expected…
Honza Pokorny
  • 3,205
  • 5
  • 37
  • 43
2
votes
1 answer

BS.getLine and CRLF endings

I'm trying to remove the \r from the end of lines when using BS.getLine. I've tried using hSetNewlineMode and it works with getLine but not with BS.getLine: import qualified Data.ByteString.Char8 as BS import Data.ByteString (ByteString) import…
ErikR
  • 51,541
  • 9
  • 73
  • 124
2
votes
0 answers

How to output an Integer array in Haskell using ByteString?

My sample code to define and fill up then output an (Integer) IOArray: {-# OPTIONS_GHC -O2 #-} {-# LANGUAGE BangPatterns #-} import Data.Array import Data.Array.IO for_ xs f = mapM_ f xs a_size = 10000 :: Int main :: IO() main = do a <-…
2
votes
1 answer

Haskell: How to use attoparsec in order to read a nested list from a ByteString

I have a text file (~ 300 MB large) with a nested list, similar to this one: [[4, 9, 11, 28, 30, 45, 55, 58, 61, 62, 63, 69, 74, 76, 77, 82, 87, 92, 93, 94, 95], [4, 9, 11, 28, 30, 45, 55, 58, 61, 62, 63, 69, 74, 76, 77, 82, 87, 92, 93, 94],[4, 9,…
mrsteve
  • 4,082
  • 1
  • 26
  • 63