streamly-bytestring: Library for streamly and bytestring interoperation.

[ bsd3, bytestring, library, stream, streamly ] [ Propose Tags ]


Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


  • No Candidates
Versions [RSS],, 0.1.1, 0.1.2, 0.1.3, 0.1.4 (info)
Change log
Dependencies base (>=4.7 && <5), base-compat (>=0.11), bytestring (>=0.10.0 && <=, streamly (>=0.8.1 && <0.8.4), transformers (>=0.4) [details]
License BSD-3-Clause
Copyright Sibi Prabakaran
Author Sibi Prabakaran
Revised Revision 5 made by adithyaov at 2023-02-28T13:09:27Z
Category Streamly, Stream, ByteString
Home page
Bug tracker
Source repo head: git clone
Uploaded by harendra at 2021-12-06T23:32:36Z
Distributions NixOS:0.1.4
Reverse Dependencies 6 direct, 3 indirect [details]
Downloads 2220 total (26 in the last 30 days)
Rating 2.5 (votes: 3) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2021-12-07 [all 2 reports]

Readme for streamly-bytestring-0.1.4

[back to package description]


Library for streamly and bytestring interoperation.

If you are writing code from scratch, please use Streamly.Data.Array.Foreign which is a generalization of ByteString and better integrated with streamly.

This library is to enable interoperation of streamly with existing code that uses ByteString.

The package provides APIs to interconvert between strict Bytestring and streamly Array Word8 and between lazy Bytestring and stream of Array Word8.

The interconversion in the case of strict Bytestring and streamly Array Word8 has no overhead as the underlying representation of ByteString and Array are the same, we just need to rewrap the data in a different type.


This is a dumb program that counts the number of bytes in a file.

import qualified Streamly.Prelude as S

import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BSL

import qualified Streamly.External.ByteString as Strict
import qualified Streamly.External.ByteString.Lazy as Lazy

import System.IO (FilePath)

strictByteStringSize :: BS.ByteString -> IO Int
strictByteStringSize bs = S.length $ S.unfold bs

lazyByteStringSize :: BSL.ByteString -> IO Int
lazyByteStringSize bsl = S.foldl' (+) 0
                         $ S.mapM strictByteStringSize
                         $ Strict.fromArray
                         $ Lazy.toChunks bsl

fileSize :: FilePath -> IO Int
fileSize path = do
    bsl <- BSL.readFile path
    lazyByteStringSize bsl