Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Use Resource for temporal file #101

Closed
Yawolf opened this issue Jul 16, 2019 · 0 comments · Fixed by #108
Closed

Use Resource for temporal file #101

Yawolf opened this issue Jul 16, 2019 · 0 comments · Fixed by #108
Assignees
Labels
improvement Improvement of existing code

Comments

@Yawolf
Copy link
Contributor

Yawolf commented Jul 16, 2019

Related with #12

To transform a String to a Protobuf schema, we need to create a temporal file. This is done this way right now:

def parseProtobufRaw[F[_]: Sync](raw: String)(
f: ProtoSource => F[FullProtocol]): F[FullProtocol] = {
val fileName = s"${Random.alphanumeric}.proto"
val path = "/tmp"
val filePath = s"$path/$fileName"
Sync[F]
.delay {
new PrintWriter(filePath) {
write(raw); close()
}
ParseProto.ProtoSource(fileName, path)
}
.flatMap(f)
.flatTap(
_ =>
Sync[F].delay(
new File(filePath).delete()
))
}

We would like to use a Cats Resource instead.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
improvement Improvement of existing code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants