streamly-bytestring: Library for streamly and bytestring interoperation.

[ bsd3, bytestring, library, stream, streamly ] [ Propose Tags ]
This version is deprecated.

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.1, 0.1.2, 0.1.3, 0.1.4, 0.2.0, 0.2.1 (info)
Change log Changelog.md
Dependencies base (>=4.7 && <5), bytestring (>=0.10.0 && <0.11), streamly (>=0.7.0 && <0.8) [details]
License BSD-3-Clause
Copyright Sibi Prabakaran
Author Sibi Prabakaran
Maintainer sibi@psibi.in
Category Streamly, Stream, ByteString
Home page https://github.com/psibi/streamly-bytestring#readme
Bug tracker https://github.com/psibi/streamly-bytestring/issues
Source repo head: git clone https://github.com/psibi/streamly-bytestring
Uploaded by psibi at 2020-01-26T05:16:43Z
Distributions NixOS:0.2.1
Reverse Dependencies 11 direct, 5 indirect [details]
Downloads 2739 total (38 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 2020-01-26 [all 1 reports]

Readme for streamly-bytestring-0.1.0.0

[back to package description]

streamly-bytestring

Library for streamly and bytestring interoperation.

Description

This package provides Streamly.External.ByteString and Streamly.External.ByteString.Lazy.

Strict ByteString

Streamly.External.ByteString provides functions to for interoperation between streamly and strict bytestring.

fromArray and toArray are used to efficiently convert between streamly's pinned array type (Streamly.Memory.Array) and bytestring.

read, writeN and write are Unfolds & Folds provided by streamly that are used to create and consume a stream of Word8. writeN is more efficient than write and should be preferred over write when possible.

Lazy Bytestring

Streamly.External.ByteString.Lazy provides functions to for interoperation between streamly and lazy bytestring.

readChunks and read are Unfolds. unfold from Streamly.Prelude can be used to create a stream of Array Word8 or a stream of Word8 from a lazy ByteString.

toChunks is defined as unfold readChunks. fromChunks can be used to create a lazy ByteString from a stream of Array Word8 chunks.

Usage

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 Strict.read bs

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

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