Comments (10)
You are right. We need two APIs that can write:
Iterator[Byte]
e.g. for piping in large moviesIterator[String]
-- this is for line by line. We need two versions of this - one to append and another to write.
from better-files.
Many large files are not always strings (e.g. a movie). Should this API then take in a Iterator[Byte]
then?
from better-files.
Agree. But could it also support easily (or implicitly) transformation from Iterator[String]
to Iterator[Byte]
? Not sure if it should insert the \n
s 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.
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.
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.
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.
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.
That won't compile - you can't have same function name with same number of arguments.
from better-files.
Cool! Thanks for supporting this feature.
from better-files.
Will release v2.16.0 over the weekend
from better-files.
Related Issues (20)
- make File serializible HOT 3
- Calling size on a broken symlink throws a NoSuchFileException,
- Switch to new codecov reporter
- Scala3 version HOT 6
- Support scala-native? HOT 2
- Use common settings style HOT 1
- Stream closed with Scala 2.12.15
- usingTemporaryDirectory should return `U` instead of `Unit` HOT 1
- is there a way to read huge gz csv file line by line of this package? HOT 1
- Make build pass on windows
- Make all side-effecty APIs use parens
- Add error handler to File.walk
- Imlement features from sbt IO
- Write self cleaning tests - no mutable vars
- Enable warnings for Scala 2.13 and above
- Generate scaladoc for all Scala versions
- Port ShapelessScannaerSpec to Scala 3
- scalaformat organize imports
- changeExtensionTo does not account for multiple dots in file name
- Directory Traversal Issue in File.unzipTo HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from better-files.