OpfsStorageFilesystem
Defined in: packages/rxdb-plugin-storage/src/filesystem/opfs-filesystem.ts:145
把文件内容写进浏览器 OPFS 的默认后端。
Implements
Constructors
Constructor
new OpfsStorageFilesystem(rootDir): OpfsStorageFilesystem;
Defined in: packages/rxdb-plugin-storage/src/filesystem/opfs-filesystem.ts:153
Parameters
| Parameter | Type | Description |
|---|---|---|
rootDir | string | 已规范化的存储根目录相对路径。 |
Returns
OpfsStorageFilesystem
Properties
lockBackend
readonly lockBackend: undefined = undefined;
Defined in: packages/rxdb-plugin-storage/src/filesystem/opfs-filesystem.ts:150
OPFS 下的跨上下文串行化由浏览器 Web Locks 承担,无需后端提供实现。
Implementation of
Methods
directoryExists()
directoryExists(directoryPath): Promise<boolean>;
Defined in: packages/rxdb-plugin-storage/src/filesystem/opfs-filesystem.ts:166
判断目录是否存在。
Parameters
| Parameter | Type |
|---|---|
directoryPath | string |
Returns
Promise<boolean>
Implementation of
StorageFilesystem.directoryExists
dispose()
dispose(): void;
Defined in: packages/rxdb-plugin-storage/src/filesystem/opfs-filesystem.ts:297
释放缓存的句柄与连接;服务销毁时调用一次。
Returns
void
Implementation of
ensureDirectory()
ensureDirectory(directoryPath): Promise<void>;
Defined in: packages/rxdb-plugin-storage/src/filesystem/opfs-filesystem.ts:161
创建目录及其缺失的父目录;已存在时是空操作。
Parameters
| Parameter | Type |
|---|---|
directoryPath | string |
Returns
Promise<void>
Implementation of
StorageFilesystem.ensureDirectory
ensureRoot()
ensureRoot(): Promise<void>;
Defined in: packages/rxdb-plugin-storage/src/filesystem/opfs-filesystem.ts:156
确保存储根目录存在;环境不支持时抛出 StorageUnavailableError。
Returns
Promise<void>
Implementation of
fileExists()
fileExists(filePath): Promise<boolean>;
Defined in: packages/rxdb-plugin-storage/src/filesystem/opfs-filesystem.ts:210
判断文件是否存在。
Parameters
| Parameter | Type |
|---|---|
filePath | string |
Returns
Promise<boolean>
Implementation of
list()
list(directoryPath): AsyncGenerator<StorageFilesystemEntry>;
Defined in: packages/rxdb-plugin-storage/src/filesystem/opfs-filesystem.ts:201
枚举目录的直属条目。
Parameters
| Parameter | Type |
|---|---|
directoryPath | string |
Returns
AsyncGenerator<StorageFilesystemEntry>
Remarks
返回惰性序列:服务层需要「先物化再删除」时会自行收集成数组, 实现方不必也不应提前物化。
Implementation of
moveDirectory()
moveDirectory(fromPath, toPath): Promise<void>;
Defined in: packages/rxdb-plugin-storage/src/filesystem/opfs-filesystem.ts:287
原生移动目录;仅在 StorageFilesystem.supportsDirectoryMove 为真时调用。
Parameters
| Parameter | Type |
|---|---|
fromPath | string |
toPath | string |
Returns
Promise<void>
Implementation of
StorageFilesystem.moveDirectory
moveFile()
moveFile(fromPath, toPath): Promise<void>;
Defined in: packages/rxdb-plugin-storage/src/filesystem/opfs-filesystem.ts:272
原生移动文件;仅在 StorageFilesystem.supportsFileMove 为真时调用。
Parameters
| Parameter | Type |
|---|---|
fromPath | string |
toPath | string |
Returns
Promise<void>
Implementation of
openRead()
openRead(filePath): Promise<ReadableStream<Uint8Array<ArrayBufferLike>>>;
Defined in: packages/rxdb-plugin-storage/src/filesystem/opfs-filesystem.ts:238
打开文件的读取流;文件不存在时抛出 NotFound。
Parameters
| Parameter | Type |
|---|---|
filePath | string |
Returns
Promise<ReadableStream<Uint8Array<ArrayBufferLike>>>
Remarks
读写隔离保证与 StorageFilesystem.readBlob 相同 —— 也就是没有保证。
Implementation of
openWrite()
openWrite(filePath): Promise<StorageFileWriter>;
Defined in: packages/rxdb-plugin-storage/src/filesystem/opfs-filesystem.ts:244
打开文件的写入句柄,缺失的父目录一并创建。
Parameters
| Parameter | Type |
|---|---|
filePath | string |
Returns
Promise<StorageFileWriter>
Implementation of
readBlob()
readBlob(filePath): Promise<Blob>;
Defined in: packages/rxdb-plugin-storage/src/filesystem/opfs-filesystem.ts:224
读取文件的完整内容。
Parameters
| Parameter | Type |
|---|---|
filePath | string |
Returns
Promise<Blob>
Remarks
不保证读写隔离:并发写入期间的返回值只承诺「读到某个字节序列」, 既可能是旧内容、新内容,也可能是两者的拼接。OPFS 后端在 File System snapshot 失效时会抛错,桌面后端按帧读取则会读到撕裂内容 —— 接口只取二者的交集, 调用方不得依赖强的那一侧,否则换后端就会静默出错。
因此串行化由服务层的路径锁负责,而不是靠这里。需要先读后写的调用方仍应用 StorageFilesystem.openRead 转存到临时文件,不要把返回值当长期快照留着。
Implementation of
removeDirectory()
removeDirectory(directoryPath): Promise<void>;
Defined in: packages/rxdb-plugin-storage/src/filesystem/opfs-filesystem.ts:180
递归删除目录;目录不存在时静默返回。
Parameters
| Parameter | Type |
|---|---|
directoryPath | string |
Returns
Promise<void>
Implementation of
StorageFilesystem.removeDirectory
removeFile()
removeFile(filePath): Promise<void>;
Defined in: packages/rxdb-plugin-storage/src/filesystem/opfs-filesystem.ts:250
删除文件;文件不存在时静默返回。
Parameters
| Parameter | Type |
|---|---|
filePath | string |
Returns
Promise<void>
Implementation of
supportsDirectoryMove()
supportsDirectoryMove(directoryPath): Promise<boolean>;
Defined in: packages/rxdb-plugin-storage/src/filesystem/opfs-filesystem.ts:282
判断目录是否支持原生移动;目录不存在时抛出 NotFound。
Parameters
| Parameter | Type |
|---|---|
directoryPath | string |
Returns
Promise<boolean>
Implementation of
StorageFilesystem.supportsDirectoryMove
supportsFileMove()
supportsFileMove(filePath): Promise<boolean>;
Defined in: packages/rxdb-plugin-storage/src/filesystem/opfs-filesystem.ts:267
判断文件是否支持原生移动。
Parameters
| Parameter | Type |
|---|---|
filePath | string |
Returns
Promise<boolean>
Remarks
文件不存在时抛出 NotFound —— 调用方据此在重命名前置检查里发现源文件已消失。