-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Add File.write(_,_)
to complete the pair, given we have File.read(_)
#107
Comments
You're right, we should have such a function preferably with an option, if the file already exists, to either append to it or overwrite it. |
Well now this is where our naming gets us into trouble... Ruby's API takes an offset as a 3rd parameter... if no offset is given the file is truncated. But we also have // not ambiguous, create a new file
File.create("output.json", JSON.encode(data)) Except we already have I tend to personally thing of read full file and write full file as the special "quick" cases... if I want to append to a file then I'd probably open it first... though that might just be me. I opened this issue literally because of the exact example above (shove some JSON to an output file) and know in many languages this can be done with a single quick function. |
It would probably be better to have two functions, File.write and File.append, though I agree that the first one is the more important. |
I'm not convinced a static function is required for every file operation though, rather than merely super-common ones. |
Well, having a static function (or an overload of an existing one) for appending is just a suggestion as I've seen these in other languages. C#, for example, has However, I'm not bothered about it being in the CLI distribution personally as it's easy enough to write your own. |
To compliment
read
we should also have:IE, a naive copy function could be written like:
The text was updated successfully, but these errors were encountered: