From Directory.ls to ByteString

I am a beginner with akka-streams, so this question will likely sound very basic.

How can I convert the stream of paths emitted by Directory.ls to a stream of ByteString?

The workflow I have in mind involves watching a specific directory for new files, which should then be individually fed to a processing pipeline.

Perhaps you can use or get inspiration from the Alpakka file connectors.

I don’t see where the logic to convert the Source[Path, NotUsed] to a Source[ByteString, NotUsed] is in the link you mentioned. Could you be more explicit, please?

If you see this, this will emit a caseclass whenever a file under the given path is created modified or deleted. But if you can write the needed functions you can do something like: Source.repeat(givenDir).delay(tickInterval).map(listAllFilesInDir).map(_.map(file => ByteString(file.getname))) (you can use mapConcat too if you want single names instead of a seq of names)

1 Like