-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from haskell-works/bytestring-support
Add bytestring support
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module HaskellWorks.Data.Streams.ByteString | ||
( streamChunks | ||
, stream | ||
) where | ||
|
||
import Data.Word | ||
import HaskellWorks.Data.Streams.Size | ||
import HaskellWorks.Data.Streams.Stream (Step (..), Stream (..)) | ||
import Prelude hiding (foldl, map, sum, zipWith) | ||
|
||
import qualified Data.ByteString as BS | ||
|
||
streamChunks :: [BS.ByteString] -> Stream Word8 | ||
streamChunks ass = Stream step (ass, 0) Unknown | ||
where step (bss, i) = case bss of | ||
cs:css -> if i < BS.length cs | ||
then Yield (BS.index cs i) (bss, i + 1) | ||
else Skip (css, 0) | ||
[] -> Done | ||
{-# INLINE [1] streamChunks #-} | ||
|
||
stream :: BS.ByteString -> Stream Word8 | ||
stream bs = Stream step (bs, 0) Unknown | ||
where step (cs, i) = if i < BS.length cs | ||
then Yield (BS.index cs i) (cs, i + 1) | ||
else Done | ||
{-# INLINE [1] stream #-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module HaskellWorks.Data.Streams.ByteString.Lazy | ||
( stream | ||
) where | ||
|
||
import Data.Word | ||
import HaskellWorks.Data.Streams.Stream (Stream (..)) | ||
|
||
import qualified Data.ByteString.Lazy as LBS | ||
import qualified HaskellWorks.Data.Streams.ByteString as BS | ||
|
||
stream :: LBS.ByteString -> Stream Word8 | ||
stream = BS.streamChunks . LBS.toChunks |