denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.3k stars 5.36k forks source link

`Deno.writeTextFile(file, string, { prepend: true })` #20085

Open jerrygreen opened 1 year ago

jerrygreen commented 1 year ago

It would be cool if prepend option would be also available in this native Deno API

lino-levan commented 1 year ago

There isn't really a reasonably efficient way of doing this. The fastest way of doing this would be renaming the file, writing the prepended text, and then appending the other file to this prepended text. This is more of a limitation of syscalls than anything.

jerrygreen commented 1 year ago

I'm pretty sure there should be an efficient way of doing this through core API like Deno.open

append and prepend are basically syntactical sugar on top of core API like this

lino-levan commented 1 year ago

I'm open to being wrong on this. I haven't touched systems programming in a while. I'm relatively confident though that at an OS (if not file-system) level, it's impossible.

lino-levan commented 1 year ago

This SO post suggests that it isn't possible, or at least isn't possible without a fancy non-portable FS.

cc @190n