Repository navigation
Replies: 2 comments
|
Hi @leitingzi, thanks for this write-up! Part of it already exists: since 0.17.0, FileKit has an experimental OPFS API ( For the rest (raw handles, permissions, persisted handles in IndexedDB, writable streams, sync access handles), I'd rather not grow the web API before 1.0: most of it is web only, and the public API gets frozen and reviewed in 0.18. Chunked reading on the web is already planned for 1.x. The best next step is #348: a real save dialog has to keep a |
|
Hi @vinceglb I agree. Keeping the API consistent across platforms is important, and adding too many Web-specific features could make the overall API more complex. I think focusing on the core cross-platform functionality is the right direction. |
Uh oh!
There was an error while loading. Please reload this page.
Overview
I would like to discuss expanding FileKit's file system capabilities on Web platforms (Kotlin/JS and Kotlin/Wasm) by leveraging the browser's native File System API.
FileKit already provides cross-platform file abstractions, file pickers, directory pickers, file savers, and basic file operations. However, the current Web implementation does not fully expose the capabilities provided by modern browser file system APIs.
The goal is not to reimplement existing FileKit functionality, but to fill the gaps between the current Web implementation and the capabilities available through the browser's File System API.
This would allow Web applications built with Kotlin Multiplatform to access more complete file system functionality while maintaining FileKit's cross-platform API design.
Motivation
The current Web implementation has some limitations compared with native platforms:
The browser File System API provides native capabilities that could help address these limitations.
Proposed Features
1. File and Directory Handles
Expose browser-native file and directory handles through a Kotlin-friendly abstraction.
Potential capabilities:
Relevant browser APIs:
FileSystemFileHandleFileSystemDirectoryHandleFileSystemHandlegetFileHandle()getDirectoryHandle()entries()keys()values()resolve()isSameEntry()2. Advanced File Operations
Extend the existing file operations only where the browser provides additional capabilities not already covered by
PlatformFile.Potential capabilities:
Relevant browser APIs:
createWritable()FileSystemWritableFileStreamwrite()truncate()seek()3. Directory Management
Expose directory management operations that are not currently available or fully supported on Web platforms.
Potential capabilities:
Relevant browser APIs:
getDirectoryHandle()getFileHandle()removeEntry()entries()move()(where supported)4. File System Permissions
Provide a unified way to query and request access permissions for user-selected files and directories.
Potential capabilities:
Relevant browser APIs:
queryPermission()requestPermission()5. Persistent File and Directory Handles
Support persistent access to previously selected files and directories.
Potential capabilities:
Relevant browser APIs:
IndexedDBFileSystemHandle6. Origin Private File System (OPFS)
Introduce an abstraction for the browser's Origin Private File System.
Unlike user-selected files and directories, OPFS provides an origin-scoped private storage space that does not require the user to select a physical directory.
Potential capabilities:
Relevant browser APIs:
navigator.storage.getDirectory()FileSystemFileHandleFileSystemDirectoryHandlecreateSyncAccessHandle()7. Random Access File I/O
Provide advanced file access for applications that need efficient binary data processing.
Potential capabilities:
Relevant browser API:
FileSystemSyncAccessHandleNote:
FileSystemSyncAccessHandleis intended for OPFS files inside dedicated Web Workers.Out of Scope / Existing Functionality
To avoid duplicating existing FileKit APIs, the following functionality should remain part of the existing API rather than being reimplemented:
PlatformFilemetadata and content access.PlatformFileread/write operations.The proposed APIs should complement these existing capabilities and expose browser-native functionality that is currently missing.
Platform Compatibility
The implementation should consider both Kotlin/JS and Kotlin/Wasm.
Browser APIs have different levels of support, so each feature should be evaluated independently.
Important considerations:
Possible API Design
The exact public API is open for discussion, but a possible direction could be:
These interfaces are only illustrative. The final API should follow FileKit's existing naming conventions, error handling, coroutine usage, and cross-platform architecture.
Suggested Implementation Phases
Phase 1 — File System Handles
Phase 2 — Advanced File Operations
Phase 3 — Persistent Access
Phase 4 — OPFS
Questions for Discussion
PlatformFileandPlatformDirectoryabstractions, or as a separate File System API?References
I would like to hear feedback from the maintainers and contributors about the API design, platform compatibility, and implementation priorities before starting the implementation.
The main objective is to make FileKit's Web and WASM file system capabilities more complete without introducing redundant APIs or compromising the existing cross-platform abstractions.
All reactions