Giter Site home page Giter Site logo

Comments (10)

pathikrit avatar pathikrit commented on June 13, 2024 1

You are right. We need two APIs that can write:

  1. Iterator[Byte] e.g. for piping in large movies
  2. Iterator[String] -- this is for line by line. We need two versions of this - one to append and another to write.

from better-files.

pathikrit avatar pathikrit commented on June 13, 2024

Many large files are not always strings (e.g. a movie). Should this API then take in a Iterator[Byte] then?

from better-files.

pishen avatar pishen commented on June 13, 2024

Agree. But could it also support easily (or implicitly) transformation from Iterator[String] to Iterator[Byte]? Not sure if it should insert the \ns in between the Strings automatically?
Since better-files supports simple function like File.appendLines(), I hope there's also a similar simple way when appending an Iterator[String].

from better-files.

pathikrit avatar pathikrit commented on June 13, 2024

Let's say you have an val lines: Iterator[String], you can simply do this:

val lines: Iterator[String] = ???
lines foreach {line => file.appendNewLine(line)}

That being said, I do see a case for writing an Iterator[Byte] to a file ...

from better-files.

pishen avatar pishen commented on June 13, 2024

As I know, Files.write() will open and close the file on each call, using lines foreach {line => file.appendLine(line)} may not be efficient if my Iterator[String] is large? I'm looking for a solution as simple as this, but more efficient.
Anyway, this could be another feature request, I can change this one to Iterator[Byte] to keep it precise.

from better-files.

pathikrit avatar pathikrit commented on June 13, 2024

Take a look at my PR: #70

I added writeBytes and printLines. The latter takes in options to either append or overwrite.

from better-files.

pishen avatar pishen commented on June 13, 2024

Would it be possible to use the same function name like this?

def write(bytes: Array[Byte])
def write(bytes: Iterator[Byte])

def appendLines(lines: String*)
def appendLines(lines: Iterator[String])

from better-files.

pathikrit avatar pathikrit commented on June 13, 2024

That won't compile - you can't have same function name with same number of arguments.

from better-files.

pishen avatar pishen commented on June 13, 2024

Cool! Thanks for supporting this feature.

from better-files.

pathikrit avatar pathikrit commented on June 13, 2024

Will release v2.16.0 over the weekend

from better-files.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.