DocumentFileCompat
Blazing fast AndroidX DocumentFile alternative for Android SAF (scoped storage). Up to ~14x faster on large directories.
Install / Use
/learn @ItzNotABug/DocumentFileCompatREADME
DocumentFileCompat
A faster alternative to AndroidX's DocumentFile.
The Problem with DocumentFile
It is horribly slow!
For almost every method, there is a query to ContentResolver.
The most common one is DocumentFile.findFile(), DocumentFile.getName() and other is building a
Custom Data Model with multiple parameters.
This can take like a horrible amount of time.
Solution
DocumentFileCompat is a drop-in replacement which gathers relevant parameters when querying for
files.
The performance can sometimes peak to 2x or quite higher, depending on the size of the folder.
Check the screenshots below:
<img src="/screenshots/filecompat_directory_perf.jpeg" height="500"/> <img src="/screenshots/filecompat_file_perf.jpeg" height="500"/>
48 whopping seconds for directory listing compared to 3.5! (Obviously, No competition with the
Native File API).
Also extracting file information does not take that much time but the improvement is still
significant.
Note: DocumentFileCompat is something that I used internally for some projects & therefore I
didn't do much of file manipulation with it (only delete files) <strike>and therefore this API does
not offer too much out of the box</strike>.
This is now a completely usable alternative to DocumentFile.
Installation
Gradle
dependencies {
implementation "com.lazygeniouz:dfc:$latest_version"
}
Maven
<dependency>
<groupId>com.lazygeniouz</groupId>
<artifactId>dfc</artifactId>
<version>$latest_version</version>
<type>aar</type>
</dependency>
Usage
Almost all of the methods & getters are identical to DocumentFile, you'll just have to replace the
imports.
Additional methods like copyTo(destination: Uri) & copyFrom(source: Uri) are added as well.
Reference:
- https://stackoverflow.com/a/42187419/6819340
- https://stackoverflow.com/a/63466997/6819340
Issues & Suggestions
Create a new issue if you experience any problem or have any suggestions.
I'll appreciate if you create a PR as well (if possible).
Finally, don't forget to ⭐️ the library! :)
Related Skills
qqbot-channel
347.2kQQ 频道管理技能。查询频道列表、子频道、成员、发帖、公告、日程等操作。使用 qqbot_channel_api 工具代理 QQ 开放平台 HTTP 接口,自动处理 Token 鉴权。当用户需要查看频道、管理子频道、查询成员、发布帖子/公告/日程时使用。
docs-writer
100.1k`docs-writer` skill instructions As an expert technical writer and editor for the Gemini CLI project, you produce accurate, clear, and consistent documentation. When asked to write, edit, or revie
model-usage
347.2kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
Design
Campus Second-Hand Trading Platform \- General Design Document (v5.0 \- React Architecture \- Complete Final Version)1\. System Overall Design 1.1. Project Overview This project aims t
