Skip to content

Commit b5fdafc

Browse files
Improved AppendOnly sample.
1 parent f9a6e7e commit b5fdafc

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

  • samples/KristofferStrube.Blazor.FileSystemAccess.WasmExample/Pages

samples/KristofferStrube.Blazor.FileSystemAccess.WasmExample/Pages/AppendOnly.razor

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,11 @@ else
5858
if (!eventArgs.Repeat && fileHandle is not null && eventArgs.Key is { Length: 1 } key && allowedChars.Contains(char.Parse(key)))
5959
{
6060
var file = await fileHandle.GetFileAsync();
61-
var writable = await fileHandle.CreateWritableAsync();
62-
if (fileText is not null)
61+
await using (var writable = await fileHandle.CreateWritableAsync(new() { KeepExistingData = true }))
6362
{
64-
await writable.WriteAsync(fileText);
63+
await writable.SeekAsync((ulong)cursorPosition);
64+
await writable.WriteAsync(key);
6565
}
66-
await writable.SeekAsync((ulong)cursorPosition);
67-
await writable.WriteAsync(key);
68-
await writable.CloseAsync();
6966
file = await fileHandle.GetFileAsync();
7067
fileText = await file.TextAsync();
7168
keyInput = key;

0 commit comments

Comments
 (0)