Comments (4)
It’d also be nice to use this to simplify testing for libraries like SQLite that go direct to the filesystem by default.
val database = fileSystem.openDatabase("data.sqlite".toPath())
fun FileSystem.openDatabase(path: Path): SqliteDatabase {
extension<SqliteExtension>().open(path)
}
interface SqliteExtension {
fun open(path: Path): SqliteDatabase
}
/**
* Returns a file system that includes the extension.
*
* @param inMemory true to return database instances that aren’t durable on disk; appropriate
* for use with FakeFileSystem. Otherwise the
* databases are written to FileSystem.SYSTEM.
*/
fun applySqlite(
fileSystem: FileSystem,
inMemory: Boolean
): FileSystem
from okio.
Some updates on extensions after a discussion with @dellisd ...
-
It might not be worth the effort to build a fully-capable SQLDelight extension targeting Android. Android’s Context APIs encapsulate the paths to the DBs, and it’s likely simpler to accept this design than to try to get Android apps to load their databases from a FileSystem.
-
Our
Mapper
should be prepared for a more sophisticated mapping than whatForwardingFileSystem
does. Consider this:val fileSystem = FileSystemBuilder() .add( "/cache".toPath(), FileSystem.SYSTEM, "/tmp/cache".toPath(), ) .add( "/downloads/movies".toPath(), FileSystem.SYSTEM, "/Volumes/media/movies".toPath(), writable = false, ) .add( "/downloads".toPath(), FileSystem.SYSTEM, "/Users/jwilson/Downloads".toPath(), ) .add( "/builds".toPath(), FakeFileSystem(), "/".toPath(), ) .build()
In this listing we target multiple underlying FileSystem
which seems quite reasonable. I also added writable = false
as a wrinkle to consider that we might reduce capabilities on a mapped FileSystem.
from okio.
I think we need more stuff to support the chroot
use case, where one FileSystem maps paths upon another.
Perhaps something like this?
interface FileSystemExtension {
fun interface Factory<E : FileSystemExtension> {
fun create(host: FileSystemExtension.Host): E
}
interface Host {
fun onPathParameter(path: Path, functionName: String, parameterName: String): Path
fun onPathResult(path: Path, functionName: String): Path
}
}
fun <E : FileSystemExtension> FileSystem.extend(
factory: FileSystemExtension.Factory<E>,
): FileSystem
This makes it a bit more annoying to create extensions, but it gives them the stuff they need to do 1:1 path mapping.
Also getting the implementation right is tricky, cause we need to potentially apply multiple layers of mappings.
from okio.
Yep, implementation is beyond tricky; it’s impossible. I can’t create a single instance of an extension because it could need different path transforms depending on which wrapped FileSystem returned it.
from okio.
Related Issues (20)
- `Closeable.use` throws NPE when `block` returns nullable HOT 1
- How to try okio wasm HOT 1
- M'y github
- IllegalArgumentException when trying to write a file HOT 2
- Add extensions to improve out-of-box experiences HOT 4
- okio.IOException: Operation not permitted. HOT 3
- Issue with folders named like 'X: Something' HOT 1
- Source#readZip() HOT 4
- Question: How do I access FileSystem in wasmJs? HOT 3
- API for File Locking
- API for unwrapping FileSystem HOT 2
- Path.relativeTo does not respect 'current directory dot'
- Windows (native build) codepage issues HOT 3
- Is there any API to set last modified time for a file? HOT 4
- Feature Request: support creation of NTFS Junctions HOT 1
- RealBufferedSource.read() with length=0 blocks until there's some data, breaking InputStream.readNBytes HOT 2
- [help] how to efficiently encode and decode custom int using unsafe
- BufferedSink.writeUtf8() not writing all content to file HOT 3
- Supports quic network protocol HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from okio.