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
1
vote
3 answers

Haskell Bytestring change ASCII?

import qualified Data.ByteString.Lazy.Char8 as BS stuff <- BS.readFile "stuff.txt" How do take a specific character from a bytestring then change its ASCII and then put it back? Do I use readInt or something? Ex: "aaaaa" ,"a" is 97 so minus 1 and…
ArchHaskeller
  • 1,270
  • 1
  • 12
  • 28
1
vote
2 answers

pattern doesn't match in haskell bytestring

I am writing a DNA translator using Haskell (bytestrings in particular). I have the following code: import Data.Maybe import Data.Monoid ((<>)) import System.Environment import qualified Data.ByteString as B import Data.ByteString.Lazy.Char8…
Bussller
  • 1,961
  • 6
  • 36
  • 50
1
vote
1 answer

Most efficient way of converting a Data.ByteString.Lazy to a CStringLen

I need to encode some data to JSON and then push is to the syslog using hsyslog. The types of the two relevant functions are: Aeson.encode :: a -> Data.ByteString.Lazy.ByteString System.Posix.Syslog.syslog :: Maybe Facility …
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
1
vote
0 answers

File .BMP: analysis and transformation

My goal is to be able to analyze and transform graphic files focusing on the color matrix. Is it better to operate a Word8 or Integer matrix? How else can we switch from ByteString to a two-dimensional matrix? Are the procedures used the most…
Alberto Capitani
  • 1,039
  • 13
  • 30
1
vote
1 answer

How to get nth byte from ByteString?

How can I get nth byte of ByteString in Haskell? I tried to find function like !! for ByteStrings, but found nothing.
Malyutin Egor
  • 127
  • 1
  • 10
1
vote
1 answer

Haskell Aeson json encoding bytestrings

I need to serialize a record in Haskell, and am trying to do it with Aeson. The problem is that some of the fields are ByteStrings, and I can't work out from the examples how to encode them. My idea is to first convert them to text via base64. …
8n8
  • 1,233
  • 1
  • 8
  • 21
1
vote
1 answer

How to save, append and read a List of tuple including Lists into a File using Data.Serialize and ByteString

Hello i am having problems reading after saving and appending a List of Tuple Lists inside a File. Saving something into a File works without problems. I am saving into a file with import qualified Data.ByteString as BS import qualified…
Ninexreaker
  • 43
  • 1
  • 6
1
vote
2 answers

Encoding and efficient IO in Haskell

Hello i am a bit confused about all the Haskell modules needed for encoding data from String to ByteString for efficient writing. I do not understand how you convert a Data.ByteString.Lazy to a Data.ByteString.Char8 and vice versa. What do i need to…
Bercovici Adrian
  • 8,794
  • 17
  • 73
  • 152
1
vote
1 answer

how to read String from file and convert to Data.ByteString for use in Data.Serialize.decode

I need to analyze a log file that contains lines like: 2018-07-11T17:25:14.07565; [ZMQ] info; Sending message to; ROne (Addr {_unAddr = "tcp://127.0.0.1:10002"}); ## MSG ##;…
haroldcarr
  • 1,523
  • 15
  • 17
1
vote
1 answer

Log all requests and responses for http-conduit

I have written this ManagerSettings to log all requests and responses for my http-conduit application. (By the way, I am importing ClassyPrelude). tracingManagerSettings :: ManagerSettings tracingManagerSettings = tlsManagerSettings {…
Robin Green
  • 32,079
  • 16
  • 104
  • 187
1
vote
1 answer

How to track progress through a streaming ByteString?

I'm using the streaming-utils streaming-utils to stream a HTTP response body. I want to track the progress similar to how bytestring-progress allows with lazy ByteStrings. I suspect something like toChunks would be necessary, then reducing some…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
1
vote
1 answer

Binary file writer adds extra byte

I'm building a Conduit that writes a binary file consisting of a header followed by a Double matrix as a row-ordered list. Here's the code: import Conduit ((.|), ConduitM, mapC, sinkFileBS, yield) import Control.Monad.Trans.Except (ExceptT) import…
jorgen
  • 3,425
  • 4
  • 31
  • 53
1
vote
1 answer

How to create a Ptr Word8 for ByteString

create, from Data.ByteString.Internal, states that it needs a Ptr Word8 in order to create a ByteString. I'm guessing this is like a reference to the head of the bytestring or something. However, I'm not sure what I should use to create a new…
Athan Clark
  • 3,886
  • 2
  • 21
  • 39
1
vote
1 answer

ByteString representation of a Double conversion

I'm writing my own WAVE parser that uses Conduit so I can stream values, one by one, through a pipeline. I get a sample from a .wav file via hGet (n is the number of bytes per sample for that wav file): bytes <- hGet h n This gives me a ByteString…
Thomas Vanhelden
  • 879
  • 8
  • 20
1
vote
2 answers

How do you add two large random bytestrings in Haskell?

I have two lazy bytestrings that were generated randomly using the DRBG package. I want to interpret these bytestrings as numbers and be able to perform addition on them. So something like a function with signature ByteString -> ByteString ->…
Hudon
  • 1,636
  • 18
  • 28