Library for streamly and bytestring interoperation.

Version on this page:0.1.2
LTS Haskell 21.7:0.2.0
Stackage Nightly 2024-02-29:0.2.1
Latest on Hackage:0.2.1

See all snapshots streamly-bytestring appears in

BSD-3-Clause licensed by Sibi Prabakaran
Maintained by [email protected]
This version can be pinned in stack with:streamly-bytestring-0.1.2@sha256:cc828f41d1c714c711d38fb213b4ed186febabba598ab080e13255f69c20b13c,2469

Module documentation for 0.1.2


Library for streamly and bytestring interoperation.

If you are writing code from scratch, please use Streamly.Memory.Array 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 Streamly
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


Changelog for streamly-bytestring


  • Fix memory bug in Strict.toArray


  • Add fromChunksIO function to Streamly.External.ByteString.Lazy module.

  • Fix build with ghc-8.0.2 and ghc-7.10.3 (#6)

  • Initial version released