Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Noe Alejandro Perez Dominguez
    @osocron
    This message was deleted
    Noe Alejandro Perez Dominguez
    @osocron

    Hello 👋 I'm writing a small library and I'm trying to read .json resource files without knowing the names of all the files in advance. It works fine locally but when I publish the library and call it from another application I get errors like: java.nio.file.FileSystemNotFoundException. This is how I'm finding the files currently:

      private val dir = File(Resource.getUrl("property.json"))
      private val matches: Iterator[File] = dir.parent.glob("**/*.json", includePath = false)

    Any help would be much appreciated!

    Pathikrit Bhowmick
    @pathikrit
    I don't think you can glob a resource url! This has nothing to do with better-files but JARs in general. Try in vanilla Java or Scala without better-files you will get same error.
    1 reply
    Ibrahim Moufti
    @Mouftizo

    Hello everyone : ) this is my first time using better-files, so apologies in advance if the question is too basic.

    My main objective is to write JSON lines to a file efficiently while maintaining referential transparency (nice to have).

    I have two main questions:

    1. Is writing to the file line by line efficient? I am assuming that having some sort of a buffer or a batch is faster than writing line by line, and I am wondering if I can use better-files to write to files in bulk
    2. How can I maintain referential transparency while writing to the file? (to my understanding I need to wrap part of the code in an IO Monad, but I am not sure what is the correct way to do this or how to run it safely). Further readings are welcome. (again, that is nice to have)

    I have created some sample code to show what I have reached so far in my code (only a snippet):

    
    import io.circe.generic.auto._, io.circe.syntax._
    
    for (u <- someList) println(u.asJson.noSpaces)
    // resulting Json (sample):
    // {"id":"1","name":"Mr Foo","roles":["Chief Foo Officer"],"phone_number":null}
    // {"id":"2","name":"Mr Bar","roles":["Chief Bar Officer"],"phone_number":null}
    // .....
    Pathikrit Bhowmick
    @pathikrit
    @Mouftizo : No writing line by line is inefficient. You should use a print writer to open a stream and write to stream. To make it referentially transparent, simply wrap in in IO. Here is an example:
      import better.files._
      import cats.effect._
    
      def write(file: File, lines: List[String]): IO[Unit] = IO {
        for {
          writer <- file.printWriter()
          line <- lines
        } writer.println(line)
      }
    1 reply
    Oliver Schrenk
    @oschrenk

    Is there some way to remove a parent tree from a file, sort of making a relative path?

    I have

    val base  = File("/Users/Oliver/Downloads")
    val other = File("/Users/Oliver/Downloads/other")

    and I want something like

    println(base.resolve(other))
    /other
    Francois Armand
    @fanf
    Hello! I was wondering if there was some utilities to set unix rights in a shorter way than:
      val defaultFolderPermissions = Set[PosixFilePermission](PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE
                                                      , PosixFilePermission.GROUP_READ, PosixFilePermission.GROUP_EXECUTE)
    something like file.setPerms(" u-x,u+rwX,g-wx,g+rX,o-rwx") (or with the binary representation) ?
    Francois Armand
    @fanf
    in related usability method: is there an utility to recursively create parent directories if they don't exist (with some rights)? (I can do it, it's just the coming from FileUtils.write(path, string), I'm used to have these parent directories created)

    something like file.setPerms(" u-x,u+rwX,g-wx,g+rX,o-rwx") (or with the binary representation) ?

    That is in the Unix dsl. See line 149: https://github.com/pathikrit/better-files/blob/master/core/src/main/scala/better/files/Dsl.scala#L149

    image.png
    Please read the README, these are all described there
    Andriy Plokhotnyuk
    @plokhotnyuk
    Hi, Pathikrit! Sorry for the off-topic... Could you, please, take part in a discussion about releasing the Dijon library? pathikrit/dijon#63
    Pathikrit Bhowmick
    @pathikrit

    Hi, Pathikrit! Sorry for the off-topic... Could you, please, take part in a discussion about releasing the Dijon library? pathikrit/dijon#63

    Sorry for some reason I had all dijon notifications muted. Let me transfer the library to someone else? Happy to work through it now...

    Andriy Plokhotnyuk
    @plokhotnyuk
    Probably it was due @scala-steward's and mine pull requests... I would like to participate in development, but, please, consider passing the ownership for somebody else who interested in that.
    Francois Armand
    @fanf
    @pathikrit sorry, I read the readme several time, for several years, and always missed that - not sure how it happens. Thanks for pointing it to me
    Francois Armand
    @fanf
    @pathikrit ok, for the create parents, I believe I didn't understand how to set the same rights than for the "last" directory ?
    Pathikrit Bhowmick
    @pathikrit

    @pathikrit ok, for the create parents, I believe I didn't understand how to set the same rights than for the "last" directory ?

    I think that part you have to do manually ... its not built in to the library.

    Francois Armand
    @fanf
    @pathikrit ok, thanks!
    and thank you for better-files, it's such a relief to use it compared to... Well, everything else :)
    Pathikrit Bhowmick
    @pathikrit
    Thank you!
    Shahed Vahabi
    @shvahabi_gitlab
    Hi eveybody, isn't better files available for Scala 3.0.0-M1, or what is the library dependency trick to import it?
    Pathikrit Bhowmick
    @pathikrit
    No I have not worked on Scala 3 ATM. Happy to accept PRs here...
    oybek
    @oybek
    Hi guys how to read file from resources folder in better-files?
    Francois Armand
    @fanf
    @oybek there is a documented Resource api: https://github.com/pathikrit/better-files#resource-apis