Skip to content

Commit 9ea5eeb

Browse files
tjramagegezihuzi
authored andcommitted
fix(fs): convert async iterator syntax to manual read (tauri-apps#2550)
1 parent 19d9d9c commit 9ea5eeb

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"fs": "patch:bug"
3+
"fs-js": "patch:bug"
4+
---
5+
6+
Fix `writeFile` ReadableStream handling due to missing async iterator support on macOS platform

plugins/fs/api-iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/fs/guest-js/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,10 +1075,18 @@ async function writeFile(
10751075

10761076
if (data instanceof ReadableStream) {
10771077
const file = await open(path, options)
1078-
for await (const chunk of data) {
1079-
await file.write(chunk)
1078+
const reader = data.getReader()
1079+
1080+
try {
1081+
while (true) {
1082+
const { done, value } = await reader.read()
1083+
if (done) break
1084+
await file.write(value)
1085+
}
1086+
} finally {
1087+
reader.releaseLock()
1088+
await file.close()
10801089
}
1081-
await file.close()
10821090
} else {
10831091
await invoke('plugin:fs|write_file', data, {
10841092
headers: {

0 commit comments

Comments
 (0)