úÎež\Ņ      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽNone !"357<IN 4A space-efficient representation of a succession of 0 vectors, supporting many efficient operations. An effectful 8 contains 8-bit bytes, or by using the operations from Data.ByteString.Streaming.Char87 it can be interpreted as containing 8-bit characters.Smart constructor for ."Yield-style smart constructor for .Reconceive an effect that results in an effectful bytestring as an effectful bytestring. Compare Streaming.mwrap. The closes equivalent of 2Streaming.wrap :: f (Stream f m r) -> Stream f m r is here  consChunk. mwrap+ is the smart constructor for the internal Go constructor.CConstruct a succession of chunks from its Church encoding (compare GHC.Exts.build) …Resolve a succession of chunks into its Church encoding; this is not a safe operation; it is equivalent to exposing the constructors VThe chunk size used for I/O. Currently set to 32k, less the memory management overhead TThe recommended chunk size. Currently set to 4k, less the memory management overhead EThe memory management overhead. Currently this is tuned for GHC only. ĸvPacking and unpacking from lists packBytes' :: Monad m => [Word8] -> ByteString m () packBytes' cs0 = packChunks 32 cs0 where packChunks n cs = case S.packUptoLenBytes n cs of (bs, []) -> Chunk bs (Empty ()) (bs, cs') -> Chunk bs (packChunks (min (n * 2) BI.smallChunkSize) cs') -- packUptoLenBytes :: Int -> [Word8] -> (ByteString, [Word8]) packUptoLenBytes len xs0 = unsafeDupablePerformIO (createUptoN' len $ p -> go p len xs0) where go !_ !n [] = return (len-n, []) go !_ !0 xs = return (len, xs) go !p !n (x:xs) = poke p x >> go (p ū 1) (n-1) xs createUptoN' :: Int -> (Ptr Word8 -> IO (Int, a)) -> IO (S.ByteString, a) createUptoN' l f = do fp <- S.mallocByteString l (l', res)  -withForeignPtr fp $ p -C f p assert (l' <= l) $ return (S.PS fp 0 l', res) {-INLINABLE packBytes' -}HConsume the chunks of an effectful ByteString with a natural right fold.PConsume the chunks of an effectful ByteString with a natural right monadic fold.VMake the information in a bytestring available to more than one eliminating fold, e.g.3Q.count 'l' $ Q.count 'o' $ Q.copy $ "hello\nworld"3 :> (2 :> ())EQ.length $ Q.count 'l' $ Q.count 'o' $ Q.copy $ Q.copy "hello\nworld"11 :> (3 :> (2 :> ()))^runResourceT $ Q.writeFile "hello2.txt" $ Q.writeFile "hello1.txt" $ Q.copy $ "hello\nworld\n":! cat hello2.txthelloworld:! cat hello1.txthelloworldSThis sort of manipulation could as well be acheived by combining folds - using  Control.Foldl• for example. But any sort of manipulation can be involved in the fold. Here are a couple of trivial complications involving splitting by lines:?let doubleLines = Q.unlines . maps (<* Q.chunk "\n" ) . Q.lines<let emphasize = Q.unlines . maps (<* Q.chunk "!" ) . Q.linesvrunResourceT $ Q.writeFile "hello2.txt" $ emphasize $ Q.writeFile "hello1.txt" $ doubleLines $ Q.copy $ "hello\nworld":! cat hello2.txthello!world!:! cat hello1.txthelloworld#As with the parallel operations in Streaming.Prelude , we have ;Q.effects . Q.copy = id hoist Q.effects . Q.copy = idÜThe duplication does not by itself involve the copying of bytestring chunks; it just makes two references to each chunk as it arises. This does, however double the number of constructors associated with each chunk.+‘’“ ”•–—˜™š›œžŸ      &‘’“ ”•–—˜™š›œžŸ h(c) Don Stewart 2006 (c) Duncan Coutts 2006-2011 (c) Michael Thompson 2015 BSD-style#what_is_it_to_do_anything@yahoo.com experimentalportableNone!"INGO(n)& Concatenate a stream of byte streams.WGiven a byte stream on a transformed monad, make it possible to 'run' transformer.MPerform the effects contained in an effectful bytestring, ignoring the bytes.Perform the effects contained in the second in an effectful pair of bytestrings, ignoring the bytes. It would typically be used at the type 0 ByteString m (ByteString m r) -> ByteString m rO(1) The empty  -- i.e.  return () Note that ByteString m w0 is generally a monoid for monoidal values of w, like () O(1) Yield a  as a minimal !O(n)( Convert a monadic stream of individual s into a packed byte stream."O(n)A Converts a packed byte stream into a stream of individual bytes.#O(c)/ Convert a monadic stream of individual strict  chunks into a byte stream.$O(c) Convert a byte stream into a stream of individual strict bytestrings. This of course exposes the internal chunk structure.%O(1) yield a strict  chunk. &O(n), Convert a byte stream into a single strict .Note that this is an  expensiveŋ operation that forces the whole monadic ByteString into memory and then copies all the data. If possible, try to avoid converting back and forth between streaming and strict bytestrings.'O(n)4 Convert a monadic byte stream into a single strict X, retaining the return value of the original pair. This operation is for use with Ą. Xmapped R.toStrict :: Monad m => Stream (ByteString m) m r -> Stream (Of ByteString) m r FIt is subject to all the objections one makes to Data.ByteString.Lazy '$; all of these are devastating. (O(c)a Transmute a pseudo-pure lazy bytestring to its representation as a monadic stream of chunks.Q.putStrLn $ Q.fromLazy "hi"hiQ.fromLazy "hi"OChunk "hi" (Empty (())) -- note: a 'show' instance works in the identity monad<Q.fromLazy $ BL.fromChunks ["here", "are", "some", "chunks"]GChunk "here" (Chunk "are" (Chunk "some" (Chunk "chunks" (Empty (()))))))O(n)5 Convert an effectful byte stream into a single lazy 1 with the same internal chunk structure. See toLazyZ which preserve connectedness by keeping the return value of the effectful bytestring.*O(n)5 Convert an effectful byte stream into a single lazy V with the same internal chunk structure, retaining the original return value. 1This is the canonical way of breaking streaming (toStrictÐ and the like are far more demonic). Essentially one is dividing the interleaved layers of effects and bytes into one immense layer of effects, followed by the memory of the succession of bytes. (Because one preserves the return value, toLazy is a suitable argument for Ą P S.mapped Q.toLazy :: Stream (ByteString m) m r -> Stream (Of L.ByteString) m rQ.toLazy "hello" "hello" :> ()HS.toListM $ traverses Q.toLazy $ Q.lines "one\ntwo\nthree\nfour\nfive\n"9["one","two","three","four","five",""] -- [L.ByteString]+O(1)\ Test whether an ByteString is empty. The value is of course in the monad of the effects.%Q.null "one\ntwo\three\nfour\nfive\n"FalseQ.null $ Q.take 0 Q.stdinTrue:t Q.null $ Q.take 0 Q.stdin0Q.null $ Q.take 0 Q.stdin :: MonadIO m => m Bool,6Remove empty ByteStrings from a stream of bytestrings.-O(1)™ Test whether a ByteString is empty, collecting its return value; -- to reach the return value, this operation must check the whole length of the string.%Q.null "one\ntwo\three\nfour\nfive\n" False :> () Q.null "" True :> ()4S.print $ mapped R.null $ Q.lines "yours,\nMeredith"FalseFalse.O1q Distinguish empty from non-empty lines, while maintaining streaming; the empty ByteStrings are on the rightDnulls :: ByteString m r -> m (Sum (ByteString m) (ByteString m) r);There are many ways to remove null bytestrings from a Stream (ByteString m) m r (besides using denull). If we pass next toAmapped nulls bs :: Stream (Sum (ByteString m) (ByteString m)) m rthen can then apply Streaming.separate to getOseparate (mapped nulls bs) :: Stream (ByteString m) (Stream (ByteString m) m) rOThe inner monad is now made of the empty bytestrings; we act on this with hoist , considering that :t Q.effects . Q.concatQ.effects . Q.concat2 :: Monad m => Stream (Q.ByteString m) m r -> m rwe have 8hoist (Q.effects . Q.concat) . separate . mapped Q.nullsK :: Monad n => Stream (Q.ByteString n) n b -> Stream (Q.ByteString n) n b0O(n/c) 0+ returns the length of a byte stream as an ĒE together with the return value. This makes various maps possible'Q.length "one\ntwo\three\nfour\nfive\n"23 :> ()MS.print $ S.take 3 $ mapped Q.length $ Q.lines "one\ntwo\three\nfour\nfive\n"3841O(1) 1! is analogous to '(:)' for lists.2O(1) Unlike 1, 'cons\''ö is strict in the ByteString that we are consing onto. More precisely, it forces the head and the first chunk. It does this because, for space efficiency, it may coalesce the new byte onto the first 'chunk' rather than starting a new 'chunk'.CSo that means you can't use a lazy recursive contruction like this: let xs = cons\' c xs in xsYou can however use 1 , as well as C and D", to build infinite byte streams.3O(n/c) Append a byte to the end of a 4O(1)D Extract the first element of a ByteString, which must be non-empty.5O(c)D Extract the first element of a ByteString, which must be non-empty.6O(1)F Extract the head and tail of a ByteString, or Nothing if it is empty7O(1)‹ Extract the head and tail of a ByteString, or its return value if it is empty. This is the 'natural' uncons for an effectful byte stream.:O(n/c)O Extract the last element of a ByteString, which must be finite and non-empty.<O(n/c) Append two=O(n) = f xs( is the ByteString obtained by applying f to each element of xs.??ū, applied to a binary operator, a starting value -- (typically the right-identity of the operator), and a ByteString, -- reduces the ByteString using the binary operator, from right to left. foldr cons = id@@ð, applied to a binary operator, a starting value (typically the left-identity of the operator), and a ByteString, reduces the ByteString using the binary operator, from left to right. We use the style of the foldl libarary for left foldsA'fold\''s keeps the return value of the left-folded bytestring. Useful for simultaneous folds over a segmented bytestreamBB f x? returns an infinite ByteString of repeated applications -- of f to x: %iterate f x == [x, f x, f (f x), ...](R.stdout $ R.take 50 $ R.iterate succ 392()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY,Q.putStrLn $ Q.take 50 $ Q.iterate succ '\''2()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYCC x! is an infinite ByteString, with x! the value of every element."R.stdout $ R.take 50 $ R.repeat 602<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<%Q.putStrLn $ Q.take 50 $ Q.repeat 'z'2zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzDDœ ties a finite ByteString into a circular one, or equivalently, the infinite repetition of the original ByteString. For an empty bytestring (like  return 17*) it of course makes an unproductive loop &Q.putStrLn $ Q.take 7 $ Q.cycle "y\n"yyyyEO(n) The F1 function is analogous to the Stream 'unfoldr'. FU builds a ByteString from a seed value. The function takes the element and returns Ģ4 if it is done producing the ByteString or returns Ī (a,b), in which case, a( is a prepending to the ByteString and b2 is used as the next element in a recursive call.Funfold is like F) but stops when the co-algebra returns ĨO; the result is the return value of the 'ByteString m r' 'unfoldr uncons = id'GO(n/c) G n, applied to a ByteString xs, returns the prefix of xs of length n, or xs itself if n > 0 xs.JNote that in the streaming context this drops the final return value; I> preserves this information, and is sometimes to be preferred.8Q.putStrLn $ Q.take 8 $ "Is there a God?" >> return TrueIs there-Q.putStrLn $ "Is there a God?" >> return TrueIs there a God?TrueCrest <- Q.putStrLn $ Q.splitAt 8 $ "Is there a God?" >> return TrueIs thereQ.effects restTrueHO(n/c) H n xs returns the suffix of xs after the first n elements, or [] if n > 0 xs.!Q.putStrLn $ Q.drop 6 "Wisconsin"sin"Q.putStrLn $ Q.drop 16 "Wisconsin"IO(n/c) I n xs is equivalent to (G n xs, H n xs).\rest <- Q.putStrLn $ Q.splitAt 3 "therapist is a danger to good hyphenation, as Knuth notes"theQ.putStrLn $ Q.splitAt 19 restrapist is a danger JJ, applied to a predicate p and a ByteString xs2, returns the longest prefix (possibly empty) of xs of elements that satisfy p.KK p is equivalent to L (Ķ . p).LL p xs? breaks the ByteString into two segments. It is equivalent to (J p xs,  dropWhile p xs)MO(n) Splits a č into components delimited by separators, where the predicate returns True for a separator element. The resulting components do not contain the separators. Two adjacent separators result in an empty component in the output. eg. TsplitWith (=='a') "aabbaca" == ["","","bb","c",""] splitWith (=='a') [] == []NO(n) Break a K into pieces separated by the byte argument, consuming the delimiter. I.e. ~split '\n' "a\nb\nd\ne" == ["a","b","d","e"] split 'a' "aXaXaXa" == ["","X","X","X",""] split 'x' "x" == ["",""]and 9intercalate [c] . split c == id split == splitWith . (==)tAs for all splitting functions in this library, this function does not copy the substrings, it just constructs new  ByteStrings" that are slices of the original.OThe OŨ function takes a ByteString and returns a list of ByteStrings such that the concatenation of the result is equal to the argument. Moreover, each sublist in the result contains only equal elements. For example, :group "Mississippi" = ["M","i","ss","i","ss","i","pp","i"]It is a special case of PA, which allows the programmer to supply their own equality test.PThe P& function is a generalized version of O.QO(n) The Q function takes a  and a list of es and concatenates the list after interspersing the first argument between each element of the list.RHcount returns the number of times its argument appears in the ByteString count = length . elemIndicesTO(n) Ty, applied to a predicate and a ByteString, returns a ByteString containing those characters that satisfy the predicate.URead entire handle contents lazily into a ,. Chunks are read on demand, in at most k9-sized chunks. It does not block waiting for a whole k-sized chunk, so if less than kS bytes are available then they will be returned immediately as a smaller chunk.The handle is closed on EOF. Note: the §* should be placed in binary mode with  for U to work correctly.VRead n bytes into a , directly from the specified §, in chunks of size k.WhGetNonBlockingN is similar to Uœ, except that it will never block waiting for data to become available, instead it returns only whatever data is available. Chunks are read on demand, in k-sized chunks.XRead entire handle contents lazily into a >. Chunks are read on demand, using the default chunk size..Once EOF is encountered, the Handle is closed. Note: the §* should be placed in binary mode with  for X to work correctly.YPipes-style nomenclature for XZPipes-style nomenclature for `[Read n bytes into a , directly from the specified §.\hGetNonBlocking is similar to [Đ, except that it will never block waiting for data to become available, instead it returns only whatever data is available. If there is no data available to be read, \ returns .ƒNote: on Windows and with Haskell implementation other than GHC, this function does not work correctly; it behaves identically to [.]Write a  to a file. Use * to ensure that the handle is closed. :set -XOverloadedStringsGrunResourceT $ Q.writeFile "hello.txt" "Hello world.\nGoodbye world.\n":! cat "hello.txt" Hello world.Goodbye world.@runResourceT $ Q.writeFile "hello2.txt" $ Q.readFile "hello.txt":! cat hello2.txt Hello world.Goodbye world.^ŒRead an entire file into a chunked 'ByteString IO ()'. The Handle will be held open until EOF is encountered. The block governed by Ļ5 will end with the closing of any handles opened.:! cat hello.txt Hello world.Goodbye world. 0runResourceT $ Q.stdout $ Q.readFile "hello.txt" Hello world.Goodbye world. _ Append a  to a file. Use * to ensure that the handle is closed. GrunResourceT $ Q.writeFile "hello.txt" "Hello world.\nGoodbye world.\n"0runResourceT $ Q.stdout $ Q.readFile "hello.txt" Hello world.Goodbye world.DrunResourceT $ Q.appendFile "hello.txt" "sincerely yours,\nArthur\n"1runResourceT $ Q.stdout $ Q.readFile "hello.txt" Hello world.Goodbye world.sincerely yours,Arthur`9getContents. Equivalent to hGetContents stdin. Will read lazilya Outputs a  to the specified §.bPipes nomenclature for acPipes-style nomenclature for putStrdA synonym for hPut, for compatibility<hPutStr :: Handle -> ByteString IO r -> IO r hPutStr = hPut\- | Write a ByteString to stdout putStr :: ByteString IO r -> IO r putStr = hPut IO.stdout/The interact function takes a function of type ByteString -> ByteStringļ as its argument. The entire input from the standard input device is passed to this function as its argument, and the resulting string is output on the standard output device. %interact morph = stdout (morph stdin)ĐĐo is a variant of findIndex, that returns the length of the string if no element is found, rather than Nothing.giTake a builder and convert it to a genuine streaming bytestring, using a specific allocation strategy.i6A simple construction of a builder from a byte stream.5let aaa = "10000 is a number\n" :: Q.ByteString IO ()'hPutBuilder IO.stdout $ toBuilder aaa10000 is a numberT !"#$%&'()*+,-./0123456789:;Š<=>?@ABCDEFGHIJKLMNOPQRSTUVWŦXYZ[\]^_`abcdŽ­ĐefghiV !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghiV !"(*)#$%'&=Q>123<T67,89KHOPLIMGJNgfihCBDEF?@A54;:0/-.+SR`Zcd^]_Yb[XUV\WaeT !"#$%&'()*+,-./0123456789:;Š<=>?@ABCDEFGHIJKLMNOPQRSTUVWŦXYZ[\]^_`abcdŽ­ĐefghiNoneINkO(n)C Convert a stream of separate characters into a packed byte stream.lO(1) Cons a Ū onto a byte stream.mO(1) Yield a Ū as a minimal nO(1) Unlike l, 'cons\''ö is strict in the ByteString that we are consing onto. More precisely, it forces the head and the first chunk. It does this because, for space efficiency, it may coalesce the new byte onto the first 'chunk' rather than starting a new 'chunk'.CSo that means you can't use a lazy recursive contruction like this: let xs = cons\' c xs in xsYou can however use l , as well as { and D&, to build infinite lazy ByteStrings.oO(n/c) Append a byte to the end of a pO(1)D Extract the first element of a ByteString, which must be non-empty.qO(1)B Extract the first element of a ByteString, which may be non-emptyrO(n/c)O Extract the last element of a ByteString, which must be finite and non-empty.uO(1)N Extract the head and tail of a ByteString, returning Nothing if it is empty.vO(n) v f xs( is the ByteString obtained by applying f to each element of xs.zz f x= returns an infinite ByteString of repeated applications of f to x:{{ x! is an infinite ByteString, with x the value of every element.|Dt ties a finite ByteString into a circular one, or equivalently, the infinite repetition of the original ByteString.| O(n) The }1 function is analogous to the Stream 'unfoldr'. }U builds a ByteString from a seed value. The function takes the element and returns Ģ4 if it is done producing the ByteString or returns Ī (a,b), in which case, a( is a prepending to the ByteString and b2 is used as the next element in a recursive call.~~, applied to a predicate p and a ByteString xs2, returns the longest prefix (possibly empty) of xs of elements that satisfy p. p is equivalent to € (Ķ . p).€€ p xs? breaks the ByteString into two segments. It is equivalent to (~ p xs,  dropWhile p xs)‚O(n) Break a O into pieces separated by the byte argument, consuming the delimiter. I.e. ~split '\n' "a\nb\nd\ne" == ["a","b","d","e"] split 'a' "aXaXaXa" == ["","X","X","X",""] split 'x' "x" == ["",""]and 9intercalate [c] . split c == id split == splitWith . (==)sAs for all splitting functions in this library, this function does not copy the substrings, it just constructs new  ByteStrings! that are slices of the original.0Q.stdout $ Q.unlines $ Q.split 'n' "banana peel"baaa peelƒO(n) ƒy, applied to a predicate and a ByteString, returns a ByteString containing those characters that satisfy the predicate.„„ĩ turns a ByteString into a connected stream of ByteStrings at divide at newline characters. The resulting strings do not contain newlines. This is the genuinely streaming „L which only breaks chunks, and thus never increases the use of memory. ?lines :: Monad m => ByteString m r -> Stream (ByteString m) m r…The …. function restores line breaks between layers ††Ī breaks a byte stream up into a succession of byte streams corresponding to words, breaking Chars representing white space. This is the genuinely streaming †p. A function that returns individual strict bytestrings would concatenate even infinitely long words like  cycle "y"ž in memory. It is best for the user who has reflected on her materials to write `mapped toStrict . words` or the like, if strict bytestrings are needed.‡The ‡ function is analogous to the … function, on words.ŽMThis will read positive or negative Ints that require 18 or fewer characters.%jklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ^ #$%&'()*+,-./089<DGHIOQUVWXYZ[\]^_`abcdfghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ^kjˆ…‡m#(%$*)'&vQwlno<ƒqpsr-.u‹89HOt€IG~‚„†,fgih{zD}|yx0/Љ+Ž`ZcdŒ^]_Yb[XUV\Wa %jklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽŊ      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopq*)9(:;<=BCX>EFIHJKMNRSTUV\rstuvZ[wxyz{|}{~€€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”{•–{•—{˜™’š›{œžŸ ĄĒĢĪ’“ĨĶstrea_AYVwWjgmZkk9k7zcCIwogA"Data.ByteString.Streaming.InternalData.ByteString.StreamingData.ByteString.Streaming.Char8 System.IOhSetBinaryModeControl.Monad.Trans.ResourceT runResourceT ByteStringEmptyChunkGobracketByteString consChunkchunkmwrap materialize dematerializedefaultChunkSizesmallChunkSize chunkOverhead packBytes packChars unpackBytes unsafeLastinlinePerformIO foldrChunks foldlChunks foldlChunksM foldrChunksM unfoldrNE unfoldMChunks unfoldrChunksrereadcopyconcat distributeeffectsdrainedempty singletonpackunpack fromChunkstoChunks fromStrict toStrict_toStrictfromLazytoLazy_toLazynull_denullnullnullslength_lengthconscons'snochead_headunconsnextByte unconsChunk nextChunklast_lastappendmap interspersefoldrfoldfold_iteraterepeatcycleunfoldMunfoldrtakedropsplitAt takeWhilebreakspan splitWithsplitgroupgroupBy intercalatecount_countfilter hGetContentsNhGetNhGetNonBlockingN hGetContents fromHandlestdinhGethGetNonBlocking writeFilereadFile appendFile getContentshPuttoHandlestdoutinteract zipWithStreamtoStreamingByteStringtoStreamingByteStringWithconcatBuilders toBuilderlinesunlineswordsunwordsstringnextCharputStrputStrLnreadIntbaseGHC.WordWord8GHC.PtrplusPtrSPECSPEC2$fMonadResourceByteString$fMonadCatchByteString$fMonadThrowByteString$fMonadBasebByteString$fMonoidByteString$fShowByteString$fIsStringByteString$fMFunctorByteString$fMonadTransByteString$fMonadIOByteString$fMonadByteString$fApplicativeByteString$fFunctorByteStringstrea_IFPpzbCt3tA58O31pIsvJiStreaming.Preludemappedghc-prim GHC.TypesIntGHC.BaseNothingJust Data.EitherLeft GHC.ClassesnotGHC.IO.Handle.TypesHandleresou_FD3YBQAG5YCJcmLlgosnndControl.Monad.Trans.ResourcefindIndexOrEnd isPrefixOfillegalBufferSizerevNonEmptyChunks revChunksChar