Open jerrygreen opened 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.
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
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.
This SO post suggests that it isn't possible, or at least isn't possible without a fancy non-portable FS.
cc @190n
Deno.writeTextFile(file, string, { append: true })
, – already works!Deno.writeTextFile(file, string, { prepend: true })
, – no such method :(It would be cool if
prepend
option would be also available in this native Deno API