streamly-bytestring

Library for streamly and bytestring interoperation.

https://github.com/psibi/streamly-bytestring#readme

Version on this page:0.2.1
LTS Haskell 21.7:0.2.0
Stackage Nightly 2024-03-07:0.2.1
Latest on Hackage:0.2.2

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.2.1@sha256:aef9bb73214f9fb67e5a13d637ff30e32755253807d0791607d24ac787067b62,2400

Module documentation for 0.2.1

streamly-bytestring

Library for streamly and bytestring interoperation.

If you are writing code from scratch, please use Streamly.Data.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 for GHC allocated memory. For foreign allocator allocated memory there is a copy involved.

Usage

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

import qualified Streamly.Data.Stream as S
import qualified Streamly.Data.Fold as FL

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.fold FL.length $ S.unfold Strict.reader bs

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

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

Changes

Changelog for streamly-bytestring

0.2.1 (Dec 2023)

  • Support streamly-core-0.2.0

0.2.0 (Mar 2023)

  • Support streamly-core-0.1.0
  • Support bytestring >= 0.3.0
  • Rename read to reader

0.1.4 (Dec 2021)

  • Support streamly-0.8.1

0.1.3 (Jul 2021)

  • Support streamly-0.8.0

0.1.2

  • Fix memory bug in Strict.toArray

0.1.1

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

0.1.0.1

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

0.1.0.0

  • Initial version released