https://github.com/akiomik/cats-nio-file
A thin scala wrapper for Java NIO.2, built on cats-effect 🐱
https://github.com/akiomik/cats-nio-file
cats cats-effect java-nio
Last synced: 6 months ago
JSON representation
A thin scala wrapper for Java NIO.2, built on cats-effect 🐱
- Host: GitHub
- URL: https://github.com/akiomik/cats-nio-file
- Owner: akiomik
- License: apache-2.0
- Created: 2019-07-21T05:21:33.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2023-06-19T23:08:40.000Z (almost 2 years ago)
- Last Synced: 2024-05-01T21:46:16.590Z (about 1 year ago)
- Topics: cats, cats-effect, java-nio
- Language: Scala
- Homepage:
- Size: 165 KB
- Stars: 13
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# cats-nio-file
[](https://index.scala-lang.org/akiomik/cats-nio-file/cats-nio-file)
[](https://github.com/akiomik/cats-nio-file/actions?query=workflow%3A%22Scala+CI%22)A thin scala wrapper for Java NIO.2, built on [cats-effect](https://typelevel.org/cats-effect/) 🐱
## Getting started
cats-nio-file is currently available for Scala 2.12, 2.13 and 3.2.
Add the following lines to your `build.sbt`.
```scala
libraryDependencies += "io.github.akiomik" %% "cats-nio-file" % "1.10.0"
```NOTE: The groupid has been changed from `com.github.akiomik` to `io.github.akiomik` because the maven repository has been changed from bintray to sonatype.
## All releases
cats-nio-file supports some different versions of cats-effect.
| cats-nio-file version | cats-effect version | scala version |
| --------------------- | ------------------- | ------------------- |
| 1.0.1 | 2.0.x | 2.12.x/2.13.x |
| 1.1.0 | 2.1.x | 2.12.x/2.13.x |
| 1.2.0 | 2.2.x | 2.12.x/2.13.x |
| 1.3.0 | 2.3.x | 2.12.x/2.13.x |
| 1.4.0 | 3.0.x | 2.12.x/2.13.x |
| 1.5.0 | 3.1.x | 2.12.x/2.13.x |
| 1.6.1 | 3.2.x | 2.12.x/2.13.x/3.0.x |
| 1.7.0 | 3.3.x | 2.12.x/2.13.x/3.1.x |
| 1.8.1 | 3.3.x | 2.12.x/2.13.x/3.2.x |
| 1.9.0 | 3.4.x | 2.12.x/2.13.x/3.2.x |
| 1.10.0 | 3.5.x | 2.12.x/2.13.x/3.2.x |## Usage
```scala
import java.util.stream.{Stream => JStream}
import java.nio.file.{Path, Paths}
import java.nio.file.attribute.PosixFilePermission
import scala.collection.mutableimport cats.effect.{IO, Resource}
import cats.nio.file.Files// File I/O operations are wrapped with `F[_]` (e.g. `IO`)
val exists: IO[Boolean] = Files[IO].exists(Paths.get("build.sbt"))// Java collections are converted to Scala collections through `scala.jdk.CollectionConverters`
val perms: IO[mutable.Set[PosixFilePermission]] = Files[IO].getPosixFilePermissions(Paths.get("build.sbt"))// `IO[JStream[A]]` values are able to convert to `Resource`
import cats.nio.file.implicits._
val list: Resource[IO, JStream[Path]] = Files[IO].list(Paths.get(".")).resource
```