Skip to content

Commit f9a6e7e

Browse files
Merge branch 'main' of github.com:KristofferStrube/Blazor.FileSystemAccess
2 parents c7b9a0c + 3f0503c commit f9a6e7e

37 files changed

Lines changed: 131 additions & 879 deletions

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
[![GitHub issues](https://img.shields.io/github/issues/KristofferStrube/Blazor.FileSystemAccess)](https://github.com/KristofferStrube/Blazor.FileSystemAccess/issues)
33
[![GitHub forks](https://img.shields.io/github/forks/KristofferStrube/Blazor.FileSystemAccess)](https://github.com/KristofferStrube/Blazor.FileSystemAccess/network/members)
44
[![GitHub stars](https://img.shields.io/github/stars/KristofferStrube/Blazor.FileSystemAccess)](https://github.com/KristofferStrube/Blazor.FileSystemAccess/stargazers)
5-
65
[![NuGet Downloads (official NuGet)](https://img.shields.io/nuget/dt/KristofferStrube.Blazor.FileSystemAccess?label=NuGet%20Downloads)](https://www.nuget.org/packages/KristofferStrube.Blazor.FileSystemAccess/)
76

87
# Introduction
@@ -19,6 +18,8 @@ On each page you can find the corresponding code for the example in the top righ
1918

2019
On the main page you can see if the API has at least minimal support in the used browser.
2120

21+
On the [Status page](https://kristofferstrube.github.io/Blazor.FileSystemAccess/Status) you can see how much of the WebIDL specs this wrapper has covered.
22+
2223
# Getting Started
2324
## Prerequisites
2425
You need to install .NET 6.0 or newer to use the library.
@@ -101,6 +102,10 @@ Feel free to open issues on the repository if you find any errors with the packa
101102

102103
A known issue is that using Streams to stream large amount of data in Blazor Server is not supported.
103104

105+
# Related repositories
106+
This project uses the *Blazor.FileSystem* package to return rich `FileSystemHandle`s both `FileSystemFileHande`s and `FileSystemDirectoryHandle`s.
107+
- https://github.com/KristofferStrube/Blazor.FileSystem
108+
104109
# Related articles
105110
This repository was build with inspiration and help from the following series of articles:
106111

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ else
1515
<label for="keyInput">Key Input: </label>
1616
<input id="keyInput" class="form-control" value=@keyInput readonly @onkeydown=KeyDown />
1717
<br />
18-
<textarea style="width:100%;height:calc(100% - 180px);" value=@fileText disabled></textarea>
18+
<textarea style="width:100%;height:calc(100vh - 280px);" value=@fileText disabled></textarea>
1919
}
2020

2121

samples/KristofferStrube.Blazor.FileSystemAccess.ServerExample/Pages/OpenFile.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ else if (fileText is null)
1818
else if (writePermissionState is PermissionState.Denied or PermissionState.Prompt)
1919
{
2020
<button @onclick="RequestWriteAccess" class="btn btn-primary">Request Write Access for @fileHandleName</button>
21-
<textarea style="width:100%;height:calc(100% - 44px);" value=@fileText @oninput=TextAreaChanged disabled="disabled"></textarea>
21+
<textarea style="width:100%;height:calc(100vh - 144px);" value=@fileText @oninput=TextAreaChanged disabled="disabled"></textarea>
2222
}
2323
else
2424
{
25-
<textarea style="width:100%;height:calc(100% - 6px);" value=@fileText @oninput=TextAreaChanged></textarea>
25+
<textarea style="width:100%;height:calc(100vh - 106px);" value=@fileText @oninput=TextAreaChanged></textarea>
2626
}
2727

2828

samples/KristofferStrube.Blazor.FileSystemAccess.ServerExample/Pages/OriginPrivate.razor

Lines changed: 0 additions & 40 deletions
This file was deleted.

samples/KristofferStrube.Blazor.FileSystemAccess.ServerExample/Pages/SaveFile.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010
else
1111
{
12-
<textarea style="width:100%;height:calc(100% - 6px);" value=@FileText @oninput=TextAreaChanged></textarea>
12+
<textarea style="width:100%;height:calc(100vh - 106px);" value=@FileText @oninput=TextAreaChanged></textarea>
1313
}
1414

1515

samples/KristofferStrube.Blazor.FileSystemAccess.ServerExample/Pages/Status.razor

Lines changed: 10 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ else
2525
{
2626
if (firstRender)
2727
{
28-
var domString = await HttpClient.GetStringAsync("https://wicg.github.io/file-system-access/");
28+
var domString = await HttpClient.GetStringAsync("https://wicg.github.io/file-system-access/#idl-index");
2929

3030
var dom = new HtmlDocument();
3131
dom.LoadHtml(domString);
@@ -40,35 +40,31 @@ else
4040
var supportedIndex = 0;
4141
while (fetchedIndex < fetchedLines.Length || supportedIndex < supportedLines.Length)
4242
{
43+
var color = "pink";
4344
if (fetchedIndex == fetchedLines.Length)
4445
{
45-
compareLines.Add($"""<span style="background-color:blue;">{supportedLines[supportedIndex]}</span>""");
46+
color = "cyan";
4647
supportedIndex++;
48+
fetchedIndex--;
4749
}
4850
else if (supportedIndex == supportedLines.Length)
4951
{
50-
compareLines.Add($"""<span style="background-color:orange;">{fetchedLines[fetchedIndex]}</span>""");
51-
fetchedIndex++;
52+
color = "lemonchiffon";
5253
}
5354
else if (fetchedLines[fetchedIndex].Trim() == supportedLines[supportedIndex].Trim())
5455
{
55-
compareLines.Add($"""<span style="background-color:lightgreen;">{fetchedLines[fetchedIndex]}</span>""");
56-
fetchedIndex++;
56+
color = "lightgreen";
5757
supportedIndex++;
5858
}
59-
else
60-
{
61-
compareLines.Add($"""<span style="background-color:pink;">{fetchedLines[fetchedIndex]}</span>""");
62-
fetchedIndex++;
63-
}
59+
compareLines.Add($"""<span style="background-color:{color};display:block;min-height:21px;">{fetchedLines[fetchedIndex++]}</span>""");
6460
}
65-
compareText = string.Join("\n", compareLines);
61+
compareText = string.Join("", compareLines);
6662
StateHasChanged();
6763
}
6864
}
6965

7066
private const string currentlySupportedWebIDL =
71-
@"enum FileSystemPermissionMode {
67+
@"enum FileSystemPermissionMode {
7268
""read"",
7369
""readwrite""
7470
};
@@ -82,78 +78,12 @@ dictionary FileSystemHandlePermissionDescriptor {
8278
FileSystemPermissionMode mode = ""read"";
8379
};
8480
85-
enum FileSystemHandleKind {
86-
""file"",
87-
""directory"",
88-
};
89-
9081
[Exposed=(Window,Worker), SecureContext, Serializable]
91-
interface FileSystemHandle {
92-
readonly attribute FileSystemHandleKind kind;
93-
readonly attribute USVString name;
94-
95-
Promise<boolean> isSameEntry(FileSystemHandle other);
96-
82+
partial interface FileSystemHandle {
9783
Promise<PermissionState> queryPermission(optional FileSystemHandlePermissionDescriptor descriptor = {});
9884
Promise<PermissionState> requestPermission(optional FileSystemHandlePermissionDescriptor descriptor = {});
9985
};
10086
101-
dictionary FileSystemCreateWritableOptions {
102-
boolean keepExistingData = false;
103-
};
104-
105-
[Exposed=(Window,Worker), SecureContext, Serializable]
106-
interface FileSystemFileHandle : FileSystemHandle {
107-
Promise<File> getFile();
108-
Promise<FileSystemWritableFileStream> createWritable(optional FileSystemCreateWritableOptions options = {});
109-
};
110-
111-
dictionary FileSystemGetFileOptions {
112-
boolean create = false;
113-
};
114-
115-
dictionary FileSystemGetDirectoryOptions {
116-
boolean create = false;
117-
};
118-
119-
dictionary FileSystemRemoveOptions {
120-
boolean recursive = false;
121-
};
122-
123-
[Exposed=(Window,Worker), SecureContext, Serializable]
124-
interface FileSystemDirectoryHandle : FileSystemHandle {
125-
async iterable<USVString, FileSystemHandle>;
126-
127-
Promise<FileSystemFileHandle> getFileHandle(USVString name, optional FileSystemGetFileOptions options = {});
128-
Promise<FileSystemDirectoryHandle> getDirectoryHandle(USVString name, optional FileSystemGetDirectoryOptions options = {});
129-
130-
Promise<undefined> removeEntry(USVString name, optional FileSystemRemoveOptions options = {});
131-
132-
Promise<sequence<USVString>?> resolve(FileSystemHandle possibleDescendant);
133-
};
134-
135-
enum WriteCommandType {
136-
""write"",
137-
""seek"",
138-
""truncate"",
139-
};
140-
141-
dictionary WriteParams {
142-
required WriteCommandType type;
143-
unsigned long long? size;
144-
unsigned long long? position;
145-
(BufferSource or Blob or USVString)? data;
146-
};
147-
148-
typedef (BufferSource or Blob or USVString or WriteParams) FileSystemWriteChunkType;
149-
150-
[Exposed=(Window,Worker), SecureContext]
151-
interface FileSystemWritableFileStream : WritableStream {
152-
Promise<undefined> write(FileSystemWriteChunkType data);
153-
Promise<undefined> seek(unsigned long long position);
154-
Promise<undefined> truncate(unsigned long long size);
155-
};
156-
15787
enum WellKnownDirectory {
15888
""desktop"",
15989
""documents"",
@@ -196,11 +126,6 @@ partial interface Window {
196126
Promise<sequence<FileSystemFileHandle>> showOpenFilePicker(optional OpenFilePickerOptions options = {});
197127
Promise<FileSystemFileHandle> showSaveFilePicker(optional SaveFilePickerOptions options = {});
198128
Promise<FileSystemDirectoryHandle> showDirectoryPicker(optional DirectoryPickerOptions options = {});
199-
};
200-
201-
[SecureContext]
202-
partial interface StorageManager {
203-
Promise<FileSystemDirectoryHandle> getDirectory();
204129
};";
205130

206131
}

samples/KristofferStrube.Blazor.FileSystemAccess.ServerExample/Program.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using KristofferStrube.Blazor.FileAPI;
2+
using KristofferStrube.Blazor.FileSystem;
23
using KristofferStrube.Blazor.FileSystemAccess;
34
using TG.Blazor.IndexedDB;
45

@@ -7,7 +8,11 @@
78
// Add services to the container.
89
builder.Services.AddRazorPages();
910
builder.Services.AddServerSideBlazor();
11+
12+
builder.Services.AddScoped(sp => new HttpClient());
13+
1014
builder.Services.AddFileSystemAccessService();
15+
builder.Services.AddStorageManagerService();
1116
builder.Services.AddURLService();
1217

1318
// Adding and configuring IndexedDB used for the IndexedDB sample.

samples/KristofferStrube.Blazor.FileSystemAccess.ServerExample/Shared/NavMenu.razor

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@
3939
<span class="oi oi-puzzle-piece" aria-hidden="true"></span> Indexed DB
4040
</NavLink>
4141
</div>
42-
<div class="nav-item px-3">
43-
<NavLink class="nav-link" href="OriginPrivate">
44-
<span class="oi oi-browser" aria-hidden="true"></span> Origin Private
45-
</NavLink>
46-
</div>
4742
<div class="nav-item px-3">
4843
<NavLink class="nav-link" href="AppendOnly">
4944
<span class="oi oi-plus" aria-hidden="true"></span> Append Only

samples/KristofferStrube.Blazor.FileSystemAccess.ServerExample/_Imports.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@using Microsoft.JSInterop
99
@using KristofferStrube.Blazor.Streams
1010
@using KristofferStrube.Blazor.FileAPI
11+
@using KristofferStrube.Blazor.FileSystem;
1112
@using KristofferStrube.Blazor.FileSystemAccess.ServerExample
1213
@using KristofferStrube.Blazor.FileSystemAccess.ServerExample.Shared
1314
@using TG.Blazor.IndexedDB;

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

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)