string package:streaming-bytestring

Promote a vanilla String into a stream. Note: Each Char is truncated to 8 bits.
Fast, effectful byte streams. This library enables fast and safe streaming of byte data, in either Word8 or Char form. It is a core addition to the streaming ecosystem and avoids the usual pitfalls of combinbing lazy ByteStrings with lazy IO. We follow the philosophy shared by streaming that "the best API is the one you already know". Thus this library mirrors the API of the bytestring library as closely as possible. See the module documentation and the README for more information.
See the simple examples of use here and the ghci examples especially in Streaming.ByteString.Char8. We begin with a slight modification of the documentation to Data.ByteString.Lazy: A time and space-efficient implementation of effectful byte streams using a stream of packed Word8 arrays, suitable for high performance use, both in terms of large data quantities, or high speed requirements. Streaming ByteStrings are encoded as streams of strict chunks of bytes. A key feature of streaming ByteStrings is the means to manipulate large or unbounded streams of data without requiring the entire sequence to be resident in memory. To take advantage of this you have to write your functions in a streaming style, e.g. classic pipeline composition. The default I/O chunk size is 32k, which should be good in most circumstances. Some operations, such as concat, append, and cons, have better complexity than their Data.ByteString equivalents, due to optimisations resulting from the list spine structure. For other operations streaming, like lazy, ByteStrings are usually within a few percent of strict ones. This module is intended to be imported qualified, to avoid name clashes with Prelude functions. eg.
import qualified Streaming.ByteString as Q
Original GHC implementation by Bryan O'Sullivan. Rewritten to use UArray by Simon Marlow. Rewritten to support slices and use ForeignPtr by David Roundy. Rewritten again and extended by Don Stewart and Duncan Coutts. Lazy variant by Duncan Coutts and Don Stewart. Streaming variant by Michael Thompson, following the ideas of Gabriel Gonzales' pipes-bytestring.
Deprecated: Use ByteStream instead.
Take a builder constructed otherwise and convert it to a genuine streaming bytestring.
>>> Q.putStrLn $ Q.toStreamingByteString $ stringUtf8 "哈斯克尔" <> stringUtf8 " " <> integerDec 98
哈斯克尔 98
This benchmark shows its performance is indistinguishable from toLazyByteString
Take a builder and convert it to a genuine streaming bytestring, using a specific allocation strategy.
Like bracket, but specialized for ByteString.