diff options
author | charlotte ✨ <charlotte@som.codes> | 2024-05-27 23:14:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-28 00:14:35 +0200 |
commit | 506c275053c880a4c6c3f49921f99fd41759064f (patch) | |
tree | 71aa767b906bb857791c2c93026eef620dcde996 /ext/fs/30_fs.js | |
parent | 35e5159c8d5987497b8980c1cf3996d241612957 (diff) |
fix(ext/fs): truncate files when a ReadableStream is passed to writeFile (#23330)
Closes #19697. This fixes a bug where the writeFile API can create
partially-overwritten files which may lead to invalid / corrupt files or
data leakage. It also aligns the behavior of writing a ReadableStream
and writing a Uint8Array to the disk.
Diffstat (limited to 'ext/fs/30_fs.js')
-rw-r--r-- | ext/fs/30_fs.js | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/ext/fs/30_fs.js b/ext/fs/30_fs.js index 3a35749d8..183e51e50 100644 --- a/ext/fs/30_fs.js +++ b/ext/fs/30_fs.js @@ -926,6 +926,7 @@ async function writeFile( append: options.append ?? false, create: options.create ?? true, createNew: options.createNew ?? false, + truncate: !(options.append ?? false), write: true, }); await data.pipeTo(file.writable, { |