@vrcalphabet/web-fs 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +131 -0
- package/dist/main.d.ts +387 -0
- package/dist/main.js +3801 -0
- package/dist/main.umd.cjs +12 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 vrcalpha
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# web-fs
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/@vrcalphabet/web-fs)
|
|
4
|
+
[](https://www.typescriptlang.org/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
TypeScriptで書かれたFile System APIを簡単に操作するためのラッパーライブラリです。
|
|
8
|
+
|
|
9
|
+
## 例
|
|
10
|
+
|
|
11
|
+
### テキストファイルの読み込み
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { pickFile } from "@vrcalphabet/web-fs";
|
|
15
|
+
|
|
16
|
+
const handle = await pickFile({
|
|
17
|
+
types: [
|
|
18
|
+
{
|
|
19
|
+
description: "テキストファイル",
|
|
20
|
+
accept: [".txt"],
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (handle) {
|
|
26
|
+
const content = await handle.text();
|
|
27
|
+
console.log(content);
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### ディレクトリ構造の表示
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { pickDirectory } from "@vrcalphabet/web-fs";
|
|
35
|
+
|
|
36
|
+
const dirHandle = await pickDirectory();
|
|
37
|
+
|
|
38
|
+
if (dirHandle) {
|
|
39
|
+
const tree = await dirHandle.treeString();
|
|
40
|
+
console.log(tree);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### ファイルの作成と書き込み
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { pickDirectory } from "@vrcalphabet/web-fs";
|
|
48
|
+
|
|
49
|
+
const dirHandle = await pickDirectory({ mode: "readwrite" });
|
|
50
|
+
|
|
51
|
+
if (dirHandle) {
|
|
52
|
+
const fileHandle = await dirHandle.createFile("example.txt");
|
|
53
|
+
if (fileHandle) {
|
|
54
|
+
await fileHandle.write("Hello, World!");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Globパターンによる検索
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { pickDirectory } from "@vrcalphabet/web-fs";
|
|
63
|
+
|
|
64
|
+
const dirHandle = await pickDirectory();
|
|
65
|
+
|
|
66
|
+
if (dirHandle) {
|
|
67
|
+
// srcディレクトリ以下のすべてのtsファイルを取得
|
|
68
|
+
const files = await dirHandle.glob("src/**/*.ts");
|
|
69
|
+
for (const file of files) {
|
|
70
|
+
console.log((await file.info()).name);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### ハンドルの永続化
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { pickFile } from "@vrcalphabet/web-fs";
|
|
79
|
+
|
|
80
|
+
// IDを指定して永続化を有効にする
|
|
81
|
+
const handle = await pickFile({
|
|
82
|
+
id: "my-text-file",
|
|
83
|
+
persistence: true,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
if (handle) {
|
|
87
|
+
// 次回以降、同じIDを指定するとピッカーを表示せずにハンドルを取得可能
|
|
88
|
+
console.log(await handle.text());
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## インストール
|
|
93
|
+
|
|
94
|
+
### npm
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
npm install @vrcalphabet/web-fs
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### yarn
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
yarn add @vrcalphabet/web-fs
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### pnpm
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
pnpm add @vrcalphabet/web-fs
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## 貢献
|
|
113
|
+
|
|
114
|
+
プロジェクトへの貢献を歓迎します!以下のルールに従うと,あなたの貢献がスムーズになります!
|
|
115
|
+
|
|
116
|
+
### Issue / PR
|
|
117
|
+
|
|
118
|
+
Issueを立てる際は,バグ報告・機能要望のどちらかを明記してください。
|
|
119
|
+
PRの説明には,目的・変更点・影響範囲・サンプルコードがあるとありがたいです。
|
|
120
|
+
|
|
121
|
+
## ライセンス
|
|
122
|
+
|
|
123
|
+
MIT License
|
|
124
|
+
|
|
125
|
+
詳細は[LICENSE](./LICENSE)ファイルを参照してください。
|
|
126
|
+
|
|
127
|
+
## 変更履歴・リリース情報
|
|
128
|
+
|
|
129
|
+
### v1.0.0 (2026-02-02)
|
|
130
|
+
|
|
131
|
+
- 初回リリース
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ディレクトリを`WebFsDirectoryHandle`でラップしたものを返します。
|
|
3
|
+
*
|
|
4
|
+
* @param directoryHandle すでに取得しているディレクトリハンドル。
|
|
5
|
+
* @param options ディレクトリのオプション。
|
|
6
|
+
* @returns 成功した場合は`WebFsDirectoryHandle`、エラーが出た場合は`undefined`。
|
|
7
|
+
*/
|
|
8
|
+
export declare function mountDirectory(directoryHandle: FileSystemDirectoryHandle, options?: WebFsPermissionOptions): Promise<WebFsDirectoryHandle | undefined>;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* ファイルを`WebFsFileHandle`でラップしたものを返します。
|
|
12
|
+
*
|
|
13
|
+
* @param fileHandle すでに取得しているファイルハンドル。
|
|
14
|
+
* @param options ファイルのオプション。
|
|
15
|
+
* @returns 成功した場合は`WebFsFileHandle`、エラーが出た場合は`undefined`。
|
|
16
|
+
*/
|
|
17
|
+
export declare function mountFile(fileHandle: FileSystemFileHandle, options?: WebFsPermissionOptions): Promise<WebFsFileHandle | undefined>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* ユーザに単一のディレクトリを選択させ、そのディレクトリを`WebFsDirectoryHandle`でラップしたものを返します。
|
|
21
|
+
*
|
|
22
|
+
* @param options ディレクトリ選択のオプション。
|
|
23
|
+
* @returns 成功した場合は`WebFsDirectoryHandle`、選択を取り消した場合やエラーが出た場合は`undefined`。
|
|
24
|
+
*/
|
|
25
|
+
export declare function pickDirectory(options?: WebFsDirectoryPickOptions): Promise<WebFsDirectoryHandle | undefined>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* ユーザに単一のファイルを選択させ、そのファイルを`WebFsFileHandle`でラップしたものを返します。
|
|
29
|
+
*
|
|
30
|
+
* @param options ファイル選択のオプション。
|
|
31
|
+
* @returns 成功した場合は`WebFsFileHandle`、選択を取り消した場合やエラーが出た場合は`undefined`。
|
|
32
|
+
*/
|
|
33
|
+
export declare function pickFile(options?: WebFsFilePickOptions): Promise<WebFsFileHandle | undefined>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* ユーザに複数のファイルを選択させ、そのファイルリストを`WebFsFileHandleList`でラップしたものを返します。
|
|
37
|
+
*
|
|
38
|
+
* @param options ファイル選択のオプション。
|
|
39
|
+
* @returns 成功した場合は`WebFsFileHandleList`、選択を取り消した場合やエラーが出た場合は`undefined`。
|
|
40
|
+
*/
|
|
41
|
+
export declare function pickFiles(options?: WebFsFilePickOptions): Promise<WebFsFileHandleList | undefined>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* ブラウザが`web-fs`に対応しているかを確認します。\
|
|
45
|
+
* 値として`false`が返った場合は、その他の関数や`WebFs*`クラスを使用できません。
|
|
46
|
+
*
|
|
47
|
+
* @returns 対応している場合は`true`、そうでない場合は`false`。
|
|
48
|
+
*/
|
|
49
|
+
export declare function supportsWebFs(): boolean;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 保存されたディレクトリハンドルを削除します。
|
|
53
|
+
*
|
|
54
|
+
* @param id 削除したいディレクトリハンドルのid。
|
|
55
|
+
*/
|
|
56
|
+
export declare function unmountDirectory(id: string): Promise<void>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 保存されたファイルハンドルを削除します。
|
|
60
|
+
*
|
|
61
|
+
* @param id 削除したいファイルハンドルのid。
|
|
62
|
+
*/
|
|
63
|
+
export declare function unmountFile(id: string): Promise<void>;
|
|
64
|
+
|
|
65
|
+
export declare class WebFsDirectoryHandle extends WebFsHandle {
|
|
66
|
+
/**
|
|
67
|
+
* ディレクトリハンドルの種類。常に`"directory"`を返します。
|
|
68
|
+
*/
|
|
69
|
+
readonly type = "directory";
|
|
70
|
+
protected _handle: FileSystemDirectoryHandle;
|
|
71
|
+
private constructor();
|
|
72
|
+
/**
|
|
73
|
+
* ファイルを`WebFsFileHandle`でラップしたものを返します。
|
|
74
|
+
*
|
|
75
|
+
* @param handle すでに取得しているファイルハンドル。
|
|
76
|
+
* @param mode ファイルのオプション。
|
|
77
|
+
* @returns 成功した場合は`WebFsFileHandle`、エラーが出た場合は`undefined`。
|
|
78
|
+
*/
|
|
79
|
+
static create(handle: FileSystemDirectoryHandle, mode?: FileSystemPermissionMode): Promise<WebFsDirectoryHandle | undefined>;
|
|
80
|
+
/**
|
|
81
|
+
* ファイルを取得します。ファイル名またはファイルの相対パスを指定します。
|
|
82
|
+
*
|
|
83
|
+
* @param filePath 取得するファイルのファイルパス。
|
|
84
|
+
* @param options ファイルのオプション。
|
|
85
|
+
* @returns ファイルが取得できた場合は`WebFsFileHandle`、`options.create`が`false`かつファイルが存在しない場合、またはエラーが出た場合は`undefined`。
|
|
86
|
+
*/
|
|
87
|
+
file(filePath: string, options?: WebFsGetFileOptions): Promise<WebFsFileHandle | undefined>;
|
|
88
|
+
/**
|
|
89
|
+
* ディレクトリを取得します。ディレクトリ名またはディレクトリの相対パスで指定します。
|
|
90
|
+
*
|
|
91
|
+
* @param dirPath 取得するディレクトリのファイルパス。
|
|
92
|
+
* @param options ディレクトリのオプション。
|
|
93
|
+
* @returns ディレクトリが取得できた場合は`WebFsDirectoryHandle`、`options.create`が`false`かつディレクトリが存在しない場合、またはエラーが出た場合は`undefined`。
|
|
94
|
+
*/
|
|
95
|
+
dir(dirPath: string, options?: WebFsGetDirectoryOptions): Promise<WebFsDirectoryHandle | undefined>;
|
|
96
|
+
/**
|
|
97
|
+
* ファイルを簡易的なglobパターンから取得します。
|
|
98
|
+
*
|
|
99
|
+
* @returns globパターンにマッチしたファイルの`WebFsFileHandle`の配列。
|
|
100
|
+
*/
|
|
101
|
+
glob(pattern: string): Promise<WebFsFileHandle[]>;
|
|
102
|
+
private _glob;
|
|
103
|
+
/**
|
|
104
|
+
* ファイルを作成します。ファイル名またはファイルの相対パスで指定します。
|
|
105
|
+
*
|
|
106
|
+
* @returns ファイルが作成できた場合はそのファイルの`WebFsFileHandle`、エラーが出た場合は`undefined`。
|
|
107
|
+
*/
|
|
108
|
+
createFile(filePath: string, options?: WebFsPermissionOptions): Promise<WebFsFileHandle | undefined>;
|
|
109
|
+
/**
|
|
110
|
+
* ディレクトリを作成します。ディレクトリ名またはディレクトリの相対パスで指定します。
|
|
111
|
+
*
|
|
112
|
+
* @returns ディレクトリが作成できた場合はそのディレクトリの`WebFsDirectoryHandle`、エラーが出た場合は`undefined`。
|
|
113
|
+
*/
|
|
114
|
+
createDir(dirPath: string, options?: WebFsPermissionOptions): Promise<WebFsDirectoryHandle | undefined>;
|
|
115
|
+
/**
|
|
116
|
+
* ファイルまたはディレクトリを削除します。削除するエントリーがディレクトリであった場合は、その子孫を再帰的に削除します。
|
|
117
|
+
*
|
|
118
|
+
* @param entryPath 削除するファイルまたはディレクトリの名前。
|
|
119
|
+
* @returns 削除に成功した場合は`true`、エントリーが存在しないまたはエラーの場合は`false`。
|
|
120
|
+
*/
|
|
121
|
+
remove(entryPath: string): Promise<boolean>;
|
|
122
|
+
/**
|
|
123
|
+
* 現在の階層にあるファイル名またはディレクトリ名の一覧を取得します。
|
|
124
|
+
*
|
|
125
|
+
* @param [options={}] 一覧のオプション。
|
|
126
|
+
* @returns ファイル名またはディレクトリ名からなる配列を返します。
|
|
127
|
+
*/
|
|
128
|
+
names({ file, dir, depth, }?: WebFsEntryListOptions): Promise<string[]>;
|
|
129
|
+
/**
|
|
130
|
+
* 現在の階層にあるファイルまたはディレクトリのハンドルの一覧を取得します。
|
|
131
|
+
*
|
|
132
|
+
* @param [options={}] 一覧のオプション。
|
|
133
|
+
* @returns ファイルハンドルまたはディレクトリハンドルからなる配列を返します。
|
|
134
|
+
*/
|
|
135
|
+
list({ file, dir, depth, }?: WebFsEntryListOptions): Promise<(WebFsFileHandle | WebFsDirectoryHandle)[]>;
|
|
136
|
+
/**
|
|
137
|
+
* ファイル構造をツリー形式として取得します。
|
|
138
|
+
*
|
|
139
|
+
* @returns ツリー形式のオブジェクト。
|
|
140
|
+
*/
|
|
141
|
+
tree({ file, dir, depth, }?: WebFsEntryListOptions): Promise<WebFsTreeResult>;
|
|
142
|
+
/**
|
|
143
|
+
* ファイル構造を文字列のツリー形式として取得します。
|
|
144
|
+
*
|
|
145
|
+
* 返り値の例:
|
|
146
|
+
* ```text
|
|
147
|
+
* babel/
|
|
148
|
+
* ├─ code-frame/
|
|
149
|
+
* │ ├─ lib/
|
|
150
|
+
* │ ├─ LICENSE
|
|
151
|
+
* │ ├─ package.json
|
|
152
|
+
* │ └─ README.md
|
|
153
|
+
* ├─ compat-data/
|
|
154
|
+
* │ ├─ data/
|
|
155
|
+
* │ ├─ corejs3-shipped-proposals.js
|
|
156
|
+
* │ ├─ plugin-bugfixes.js
|
|
157
|
+
* │ ├─ corejs2-built-ins.js
|
|
158
|
+
* ...
|
|
159
|
+
* ```
|
|
160
|
+
*
|
|
161
|
+
* @returns ツリー形式の文字列。
|
|
162
|
+
*/
|
|
163
|
+
treeString({ file, dir, depth, }?: WebFsEntryListOptions): Promise<string>;
|
|
164
|
+
private _tree;
|
|
165
|
+
private _flat;
|
|
166
|
+
private _toString;
|
|
167
|
+
private _filterEntry;
|
|
168
|
+
private _dirByPath;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** ディレクトリを選択する際のオプションです。 */
|
|
172
|
+
export declare type WebFsDirectoryPickOptions = WebFsPickOptions & {};
|
|
173
|
+
|
|
174
|
+
/** エントリーリストを取得する際のオプションです。 */
|
|
175
|
+
export declare interface WebFsEntryListOptions {
|
|
176
|
+
/** 要素にファイルハンドルを含めるかを指定します。デフォルトは`true`です。 */
|
|
177
|
+
file?: boolean;
|
|
178
|
+
/** 要素にディレクトリハンドルを含めるかを指定します。デフォルトは`true`です。 */
|
|
179
|
+
dir?: boolean;
|
|
180
|
+
/** 再帰する深さを指定します。デフォルトは`1`です。 */
|
|
181
|
+
depth?: number;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export declare class WebFsFileHandle extends WebFsHandle {
|
|
185
|
+
/**
|
|
186
|
+
* ファイルハンドルの種類。常に`"file"`を返します。
|
|
187
|
+
*/
|
|
188
|
+
readonly type = "file";
|
|
189
|
+
protected _handle: FileSystemFileHandle;
|
|
190
|
+
private constructor();
|
|
191
|
+
/**
|
|
192
|
+
* ファイルを`WebFsFileHandle`でラップしたものを返します。
|
|
193
|
+
*
|
|
194
|
+
* @param handle すでに取得しているファイルハンドル。
|
|
195
|
+
* @param mode ファイルのオプション。
|
|
196
|
+
* @returns 成功した場合は`WebFsFileHandle`、エラーが出た場合は`undefined`。
|
|
197
|
+
*/
|
|
198
|
+
static create(handle: FileSystemFileHandle, mode?: FileSystemPermissionMode): Promise<WebFsFileHandle | undefined>;
|
|
199
|
+
/**
|
|
200
|
+
* ファイルの情報を返します。\
|
|
201
|
+
* これには、ファイル名、ファイルサイズ、MIMEの種類、パス、最終更新日時が含まれます。
|
|
202
|
+
*
|
|
203
|
+
* @returns ファイルの情報。
|
|
204
|
+
*/
|
|
205
|
+
info(): Promise<WebFsFileInfo>;
|
|
206
|
+
/**
|
|
207
|
+
* ファイルの内容をUTF-8形式の文字列として取得します。
|
|
208
|
+
*
|
|
209
|
+
* @returns ファイルの内容を解釈した文字列を返します。
|
|
210
|
+
*/
|
|
211
|
+
text(): Promise<string>;
|
|
212
|
+
/**
|
|
213
|
+
* ファイルの内容をUTF-8形式のJSONと解釈したうえで、オブジェクトに変換して返します。
|
|
214
|
+
*
|
|
215
|
+
* @returns 有効なJSON構文である場合は`unknown`、そうでない場合は`undefined`が返ります。
|
|
216
|
+
*/
|
|
217
|
+
json<T = unknown>(): Promise<T | undefined>;
|
|
218
|
+
/**
|
|
219
|
+
* ファイルを`Blob`として取得します。
|
|
220
|
+
*
|
|
221
|
+
* @returns ファイルの`Blob`オブジェクト。
|
|
222
|
+
*/
|
|
223
|
+
blob(): Promise<Blob>;
|
|
224
|
+
/**
|
|
225
|
+
* ファイルを`arrayBuffer`として取得します。
|
|
226
|
+
*
|
|
227
|
+
* @returns ファイルの`arrayBuffer`オブジェクト。
|
|
228
|
+
*/
|
|
229
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
230
|
+
/**
|
|
231
|
+
* ファイルのハッシュ値を取得します。\
|
|
232
|
+
* ハッシュ値のアルゴリズムは、`md5`、`sha256`、`sha512`から選べます。
|
|
233
|
+
*
|
|
234
|
+
* @returns ハッシュ化された16進数の文字列。
|
|
235
|
+
*/
|
|
236
|
+
hash(algo?: WebFsFileHashType): Promise<string>;
|
|
237
|
+
/**
|
|
238
|
+
* ファイルの内容を`data`の内容で**上書き**します。
|
|
239
|
+
*
|
|
240
|
+
* @returns ファイルの書き込みに成功した場合は`true`、失敗した場合は`false`。
|
|
241
|
+
*/
|
|
242
|
+
write(data: string): Promise<boolean>;
|
|
243
|
+
/**
|
|
244
|
+
* ファイルの内容に`data`の内容を追記します。
|
|
245
|
+
*
|
|
246
|
+
* @returns ファイルの書き込みに成功した場合は`true`、失敗した場合は`false`。
|
|
247
|
+
*/
|
|
248
|
+
append(data: string): Promise<boolean>;
|
|
249
|
+
/**
|
|
250
|
+
* ファイルの読み込みストリームを取得します。
|
|
251
|
+
*
|
|
252
|
+
* @returns ファイルの読み込みストリーム。
|
|
253
|
+
*/
|
|
254
|
+
readStream(): Promise<ReturnType<Blob["stream"]>>;
|
|
255
|
+
/**
|
|
256
|
+
* ファイルの書き込みストリームを取得します。
|
|
257
|
+
*
|
|
258
|
+
* @returns ファイルの書き込みストリーム。
|
|
259
|
+
*/
|
|
260
|
+
writeStream(options?: FileSystemCreateWritableOptions): Promise<FileSystemWritableFileStream>;
|
|
261
|
+
private _write;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
declare class WebFsFileHandleList {
|
|
265
|
+
private _handles;
|
|
266
|
+
private constructor();
|
|
267
|
+
/**
|
|
268
|
+
* ファイルを`WebFsFileHandleList`(`WebFsFileHandle`の配列)でラップしたものを返します。
|
|
269
|
+
*
|
|
270
|
+
* @param handles すでに取得しているファイルハンドルの配列。
|
|
271
|
+
* @param mode ファイルのオプション。
|
|
272
|
+
* @returns 成功した場合は`WebFsFileHandleList`、エラーが出た場合は`undefined`。
|
|
273
|
+
*/
|
|
274
|
+
static create(handles: FileSystemFileHandle[], mode?: FileSystemPermissionMode): Promise<WebFsFileHandleList | undefined>;
|
|
275
|
+
/**
|
|
276
|
+
* ファイルを取得します。
|
|
277
|
+
*
|
|
278
|
+
* @param fileName 取得するファイルのファイル名。
|
|
279
|
+
* @returns ファイルが取得できた場合は`WebFsFileHandle`、存在しない場合は`undefined`。
|
|
280
|
+
*/
|
|
281
|
+
file(fileName: string): WebFsFileHandle | undefined;
|
|
282
|
+
/**
|
|
283
|
+
* ファイル名の一覧を取得します。
|
|
284
|
+
*
|
|
285
|
+
* @returns ファイル名の配列を返します。
|
|
286
|
+
*/
|
|
287
|
+
names(): string[];
|
|
288
|
+
/**
|
|
289
|
+
* ファイルハンドルの一覧を取得します。
|
|
290
|
+
*
|
|
291
|
+
* @returns ファイルハンドルの配列を返します。
|
|
292
|
+
*/
|
|
293
|
+
list(): WebFsFileHandle[];
|
|
294
|
+
/**
|
|
295
|
+
* 現在の`WebFsFileHandleList`インスタンスが管理しているファイルハンドルの数を取得します。
|
|
296
|
+
*/
|
|
297
|
+
get length(): number;
|
|
298
|
+
[Symbol.iterator](): Generator<WebFsFileHandle, void, unknown>;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** ハッシュ化するアルゴリズムの種類です。 */
|
|
302
|
+
export declare type WebFsFileHashType = "md5" | "sha256" | "sha512";
|
|
303
|
+
|
|
304
|
+
export declare interface WebFsFileInfo {
|
|
305
|
+
/** ファイルの名前です。 */
|
|
306
|
+
name: string;
|
|
307
|
+
/** ファイルサイズです。単位はバイトです。 */
|
|
308
|
+
size: number;
|
|
309
|
+
/** ファイルのMIMEタイプです。 */
|
|
310
|
+
mimeType: string;
|
|
311
|
+
/** ファイルの最終更新日時です。 */
|
|
312
|
+
lastModified: number;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** ファイルを選択する際のオプションです。 */
|
|
316
|
+
export declare type WebFsFilePickOptions = WebFsPickOptions & {
|
|
317
|
+
/** 指定されている拡張子とは別に、すべての拡張子を許可する項目を追加します。 */
|
|
318
|
+
acceptAllExtensions?: boolean;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
/** ファイルの種類を定義するオブジェクトです。 */
|
|
322
|
+
export declare interface WebFsFilePickType {
|
|
323
|
+
/** ファイルの種類の、ユーザー向けの説明です。 */
|
|
324
|
+
description?: string;
|
|
325
|
+
/** 許可するMIMEタイプと拡張子のリストです。 */
|
|
326
|
+
accept: FileExtension[];
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** ディレクトリを取得する際のオプションです。 */
|
|
330
|
+
export declare interface WebFsGetDirectoryOptions extends FileSystemGetDirectoryOptions, WebFsPermissionOptions {
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/** ファイルを取得する際のオプションです。 */
|
|
334
|
+
export declare interface WebFsGetFileOptions extends FileSystemGetFileOptions, WebFsPermissionOptions {
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export declare abstract class WebFsHandle {
|
|
338
|
+
abstract readonly type: "file" | "directory";
|
|
339
|
+
protected _handle: FileSystemHandle;
|
|
340
|
+
protected constructor(handle: FileSystemHandle);
|
|
341
|
+
/**
|
|
342
|
+
* ファイルハンドルの名前。ファイル名やディレクトリ名を表します。
|
|
343
|
+
*/
|
|
344
|
+
get name(): string;
|
|
345
|
+
protected _verifyPermission(mode: FileSystemPermissionMode): Promise<boolean>;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** 権限に関するオプションです。 */
|
|
349
|
+
export declare interface WebFsPermissionOptions {
|
|
350
|
+
/** ファイルやディレクトリに対する権限を、`"read"`または`"readwrite"`で指定します。 */
|
|
351
|
+
mode?: FileSystemPermissionMode;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** ファイルやディレクトリを選択する際の共通オプションです。 */
|
|
355
|
+
export declare type WebFsPickOptions = {
|
|
356
|
+
/** ファイルやディレクトリに対する権限を、`"read"`または`"readwrite"`で指定します。 */
|
|
357
|
+
mode?: FileSystemPermissionMode;
|
|
358
|
+
/** ダイアログを開く際の初期ディレクトリを指定します。 */
|
|
359
|
+
startIn?: WellKnownDirectory;
|
|
360
|
+
/** 選択可能なファイルの種類を指定します。 */
|
|
361
|
+
types?: WebFsFilePickType[];
|
|
362
|
+
} & ({
|
|
363
|
+
/** 設定を保存するためのIDです。 */
|
|
364
|
+
id: string;
|
|
365
|
+
/** 永続化するかどうかを指定します。 */
|
|
366
|
+
persistence: true;
|
|
367
|
+
} | {
|
|
368
|
+
/** 設定を保存するためのIDです。 */
|
|
369
|
+
id?: string;
|
|
370
|
+
/** 永続化するかどうかを指定します。 */
|
|
371
|
+
persistence?: false;
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
/** ツリー形式のファイル構造を表すオブジェクトです。 */
|
|
375
|
+
export declare type WebFsTreeResult = {
|
|
376
|
+
/** ディレクトリハンドルです。 */
|
|
377
|
+
handle: FileSystemFileHandle;
|
|
378
|
+
/** ディレクトリ内の子要素のリストです。 */
|
|
379
|
+
children: undefined;
|
|
380
|
+
} | {
|
|
381
|
+
/** ディレクトリハンドルです。 */
|
|
382
|
+
handle: FileSystemDirectoryHandle;
|
|
383
|
+
/** ディレクトリ内の子要素のリストです。 */
|
|
384
|
+
children: WebFsTreeResult[];
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
export { }
|