by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Bloznelis
    @Bloznelis
      def canonicalFile: File =
        toJava.getCanonicalFile.toScala
    Pathikrit Bhowmick
    @pathikrit
    @Bloznelis : yes that is intended
    Sait Sami Kocataş
    @Deliganli

    hi Guys

    when I give a config string like below

    File("~/some/directory")

    it outputs;
    in windows: C:\Users\myuser\projects\myproject\~\some\directory
    in linux : /home/myuser/projects/myproject/~/some/directory

    I would expect it to output;
    in windows: C:\Users\myuser\some\directory
    in linux: /home/myuser/some/directory

    but File.home is pointing to correct directory
    projects/myproject is the classpath of the running application

    am I doing something wrong?

    Pathikrit Bhowmick
    @pathikrit
    @Deliganli : ~ is not a standard construct. Try File.currentWorkingDirectory / "some" / "directory"
    Sait Sami Kocataş
    @Deliganli

    @pathikrit thanks

    I needed to implement something for my usage below

    val PathRegex = """^(?:\~\/)(\.?.*)""".r
    
      implicit class FileAugmentations(file: String) {
    
        def toFile: File = file match {
          case PathRegex(paths) =>
            File.home / paths
          case absolute =>
            File(absolute)
        }
      }

    issue is I will be getting the strings from config files so cannot use code until I reason with the string

    Pathikrit Bhowmick
    @pathikrit
    @Deliganli : Yes it won't work. I don't think it is a issue with better-files but the JDK itself. Try using vanilla java.io.File or java.nio.Path and see if it works there? If yes, let me know ...
    iOgre
    @iOgre_gitlab
    Greetings!
    Why File("zzz").changeExtensionTo("ddd").name gives "zzz" and not "zzz.ddd" ?
    Pathikrit Bhowmick
    @pathikrit
    Because zzz does not have a extension already - I think you are right - this should give zzz.ddd
    vimalaguti
    @vimalaguti
    Hi, I'm generating the scala api documentation for my project, but the better-files api documentation is getting also included. Any idea on how to remove it from my project-doc?
    Pathikrit Bhowmick
    @pathikrit
    @vimalaguti: You mean scaladoc is being generated? If you add better-files as a sbt dependency instead of copying it, it should not happen
    vimalaguti
    @vimalaguti
    better-files is a dependency, when I generate the scaladoc for my project I also found the better-files' one
    Pathikrit Bhowmick
    @pathikrit
    @vimalaguti : can you post your build file and/or file an issue on github with better-files? this is strange
    vimalaguti
    @vimalaguti
    i'll try to open an issue with the above infos, thank you
    Tomas Klubal
    @blondacz
    Hello, can u pls tell me how do I read a zip file with one entry from classpath and map it to string? Thx
    Pathikrit Bhowmick
    @pathikrit
    @blondacz : What do you mean by mapping to String?
    Eric Peters
    @er1c
    @pathikrit got a few PRs put in, not sure what you prefer, bigger or smaller PRs? should I ask you about features before submitting a PR?
    Pathikrit Bhowmick
    @pathikrit
    Smaller PRs and yeah feel free to message me
    Eric Peters
    @er1c
    What's up with the CI, seems like it just keeps running lol
    Eric Peters
    @er1c
    Draft PR for a bunch of IO stuff: pathikrit/better-files#431
    Pathikrit Bhowmick
    @pathikrit
    Great thanks! Will take a look and comment/merge as necessary!
    Eric Peters
    @er1c
    definitely not ready for merge :)
    I have a TODO to add some notes and try and explain the various functionality, the tests are the best resources
    oh the non "big pr" should be fine :)
    Alexander Aumann
    @aumann
    Hi, I've seen that JDK 8 has been removed from tests from 3.9.0 onwards. Does this mean better-files will not work as expected on Java 8 anymore?
    Alexander Aumann
    @aumann
    Ah, ok. I've found pathikrit/better-files#417 -- i.e. it should work I guess?
    Pathikrit Bhowmick
    @pathikrit
    Eric Peters
    @er1c
    @pathikrit not sure if you had a chance to glance at the resource PR to get an initial impression on functionality? One idea I just had was making a better-resources instead of adding to better.files.resources, not sure if you have an initial impression? There is definitely some overlap on compression stuff, I haven't had a chance yet to see how much can be refactored
    the "Scala I/O f or humans" does feel like it would align with the goals if its not just File i/o (e.g. InputStreams/etc)
    Pathikrit Bhowmick
    @pathikrit
    I agree - I plan to take a look at the larger PRs later this week
    Eric Peters
    @er1c
    Eric Peters
    @er1c
    @pathikrit any chance to review the AnyVal PR?
    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.
    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)
      }