From 1a5ca66e83504c85e437f378f3a50681144cc71a Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Mon, 13 May 2024 13:27:18 -0500 Subject: [PATCH] fix: Pipes.Node.FS.read' --- src/Pipes.Node.FS.purs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Pipes.Node.FS.purs b/src/Pipes.Node.FS.purs index f293f85..7e1ffec 100644 --- a/src/Pipes.Node.FS.purs +++ b/src/Pipes.Node.FS.purs @@ -8,7 +8,7 @@ import Effect.Aff.Class (class MonadAff) import Effect.Class (liftEffect) import Effect.Exception (Error) import Node.Buffer (Buffer) -import Node.FS.Stream (WriteStreamOptions) +import Node.FS.Stream (WriteStreamOptions, ReadStreamOptions) import Node.FS.Stream as FS.Stream import Node.Path (FilePath) import Node.Stream.Object as O @@ -61,3 +61,19 @@ read :: forall m. MonadAff m => MonadThrow Error m => FilePath -> Producer (Mayb read p = do r <- liftEffect $ FS.Stream.createReadStream p fromReadable $ O.fromBufferReadable r + +-- | Creates a `fs.Readable` stream for the file at the given path. +-- | +-- | Emits `Nothing` before closing. To opt out of this behavior, +-- | use `Pipes.Node.Stream.withoutEOS` or `Pipes.Node.Stream.unEOS`. +read' + :: forall r trash m + . Union r trash ReadStreamOptions + => MonadAff m + => MonadThrow Error m + => Record r + -> FilePath + -> Producer (Maybe Buffer) m Unit +read' opts p = do + r <- liftEffect $ FS.Stream.createReadStream' p opts + fromReadable $ O.fromBufferReadable r