explicity truncate files when not keeping existing data
Release / release (push) Successful in 23s

This commit is contained in:
2026-02-15 20:51:17 -08:00
parent bbd975feb6
commit e99fc35e25
2 changed files with 7 additions and 3 deletions
+5 -2
View File
@@ -5,8 +5,11 @@ const cwd_directory_handle = new NodeFileSystemDirectoryHandle('.')
const test_directory_handle = await cwd_directory_handle.getDirectoryHandle('test', { 'create': true })
for (let i = 0; i < 10000; i++) {
const file_handle = await test_directory_handle.getFileHandle(i+'.txt', { 'create': true })
const writable = await file_handle.createWritable()
await writable.write('Hello World!')
let writable = await file_handle.createWritable()
await writable.write(textText+textText)
await writable.close()
writable = await file_handle.createWritable()
await writable.write(textText)
await writable.close()
const file = await file_handle.getFile()
const text = await file.text()
+2 -1
View File
@@ -14,8 +14,9 @@ export default class NodeFileSystemWritableFileStream extends WritableStream imp
constructor(name: string, options: FileSystemCreateWritableOptions = {}) {
name = path.normalize(name)
let flags = 'w'
if (!options.keepExistingData) flags = 'r+'
if (options.keepExistingData) flags = 'r+'
const fd = fs.openSync(name, flags)
if (!options.keepExistingData) fs.ftruncateSync(fd, 0)
super(Writable.toWeb(fs.createWriteStream(name, { "fd": fd })))
this.#fd = fd
}