Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/readable-stream-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"fs": "patch:bug"
"fs-js": "patch:bug"
---

Fix `writeFile` ReadableStream handling due to missing async iterator support on macOS platform
2 changes: 1 addition & 1 deletion plugins/fs/api-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions plugins/fs/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1075,10 +1075,18 @@ async function writeFile(

if (data instanceof ReadableStream) {
const file = await open(path, options)
for await (const chunk of data) {
await file.write(chunk)
const reader = data.getReader()

try {
while (true) {
const { done, value } = await reader.read()
if (done) break
await file.write(value)
}
} finally {
reader.releaseLock()
await file.close()
}
await file.close()
} else {
await invoke('plugin:fs|write_file', data, {
headers: {
Expand Down
Loading