Say I have a text file with the following content:
AAA
BBB
CCC
And I want to use the File System API to insert a new row in this file, in order to get the following:
AAA
XXX
BBB
CCC
For that I have the following code:
const [fileHandle] = await window.showOpenFilePicker()
const writable = await fileHandle.createWritable({ keepExistingData: true })
await writable.write({
type: "write",
position: 4,
data: "XXX",
})
await writable.close()
However the result is the following:
AAA
XXX
CCC
Is there a way to achieve this without loading the whole content of the file in memory and then overwriting?