purescript-node-stream-pipes/README.md

43 lines
1002 B
Markdown
Raw Normal View History

2024-05-09 22:33:44 +00:00
# purescript-node-stream-pipes
2024-05-09 22:21:15 +00:00
2024-05-09 22:33:44 +00:00
Interact with node streams in object mode using [`Pipes`]!
2024-05-09 22:21:15 +00:00
2024-05-09 22:33:44 +00:00
## Example
2024-05-09 22:21:15 +00:00
```purescript
import Prelude
2024-05-09 22:33:44 +00:00
import Effect.Aff (launchAff_)
2024-05-09 22:21:15 +00:00
import Effect (Effect)
import Effect.Class (liftEffect)
2024-05-09 22:33:44 +00:00
import Effect.Console (log)
import Pipes.Prelude ((>->))
import Pipes.Prelude as Pipes
import Pipes.Core as Pipes.Core
import Pipes.Node.FS.Stream as FS
import Pipes.Node.Zlib as Zlib
import Pipes.CSV.Parse as CSV.Parse
-- == my-zipped-data.csv ==
-- id,foo,is_deleted
-- 1,hello,f
-- 2,goodbye,t
-- Logs:
-- {id: 1, foo: "hello", is_deleted: false}
-- {id: 2, foo: "goodbye", is_deleted: true}
2024-05-09 22:21:15 +00:00
main :: Effect Unit
2024-05-09 22:33:44 +00:00
main =
Pipes.Core.runEffect
$ FS.createReadStream "my-zipped-data.csv.gz"
>-> Zlib.gunzip
>-> CSV.Parse.parse @{id :: Int, foo :: String, is_deleted :: Boolean}
>-> Pipes.mapM (liftEffect <<< log)
2024-05-09 22:21:15 +00:00
```
2024-05-09 22:33:44 +00:00
## Installing
```bash
spago install node-stream-pipes
2024-05-09 22:21:15 +00:00
```
2024-05-09 22:33:44 +00:00
[`Pipes`]: https://pursuit.purescript.org/packages/purescript-pipes/8.0.0