Compare commits

...
Sign in to create a new pull request.
Author SHA1 Message Date
f3cae4d09a Update conduitFileStream.hs 2025-06-29 19:48:42 +00:00

View file

@ -8,23 +8,22 @@ module Main where
import qualified Data.Conduit.Combinators as CC
import Data.Conduit
import Data.Text (pack,unpack)
import Data.Text
import System.Environment (getArgs)
import System.IO (stdout)
import System.FilePath (takeExtension)
import Conduit
-- | Recursively list all files in the given directory, streaming each file path as UTF-8 bytes to stdout.
listFiles :: FilePath -> IO ()
-- | Recursively list all files in the given directory
listFiles :: FilePath -> IO [FilePath]
listFiles dir = runConduitRes $
-- 1) Walk the directory (produces `FilePath`)
CC.sourceDirectoryDeep False dir
.| -- 2) Filter *before* converting to Text
filterC (\fp -> takeExtension fp == ".mdx")
.| -- 3) Convert to Text, append newline, then encode
CC.map (\fp -> pack fp <> "\n")
.| CC.encodeUtf8
.| CC.sinkHandle stdout
.| filterC (\fp -> takeExtension fp == ".mdx")
{- .| CC.sinkList -- we probably want to enrich the pipeline by not storing things until we're done processing them.
-- what i mean is that we didnt build the necessary data for constructing the program yet.
-}
.| CC.iterM -- IMPLEMENT function here
-- | Entry point: use first CLI argument as directory, defaulting to current directory.
@ -34,4 +33,5 @@ main = do
let targetDir = case args of
(d:_) -> d
[] -> "."
listFiles targetDir
paths <- listFiles targetDir
mapM_ putStrLn paths