Comments (2)
In Okio, the path is a value which represents just that: the file path. There is no intrinsic information that ties it to a particular file system. This is in contrast to java.io.File
which is tied to the system file system, or java.nio.file.Path
which is tied to a particular java.nio.file.FileSystem
.
If you have a path which represents /tmp/hello.txt
and I have the same path, reading the file will (probably) produce different results because we have different machines. The path is the same value, the file system is the system file system on both machines but the machines are different. The path doesn't know that, though, and is likely valid on both (or any) machine.
If you have the path META-INT/MANIFEST.MF
and you read it from two different .jar
files (using zip filesystem) you'll get different results. The path is the same, but the file system is different. The path doesn't know that, it's valid anywhere since it's just a value.
In your case, you have a path /root/file.txt
and you are writing to that on the fake file system instance and then attempting to read it from the system file system (by virtue of first converting it to a File
). You are writing in one place and reading from another.
The only time toFile()
will return a File
that points to the same reference is if you were using FileSystem.SYSTEM
.
Another way to think about it is to create two instances of FakeFileSystem
. If you write to one and then read from the other you will not see the correct size.
By calling toFile()
you are taking the path and passing it to a different system that only knows how to read from the system file system.
from okio.
Thanks for the detailed and awesome explanation!
from okio.
Related Issues (20)
- Musing about allocate() and allocateDirect() and WASM HOT 1
- Potential file leak in `FileSystem.read()` method HOT 9
- Feature request: set endianess at library level HOT 3
- Invalid java classname in GzipSource.kt HOT 5
- Is exposing flush in Sink a good idea ? HOT 2
- Gradle reports that okio references itself HOT 2
- Add target `watchosDeviceArm64` HOT 2
- Publish okio-fakefilesystem with wasm support HOT 1
- NullPointerException on commonCompleteSegmentByteCount HOT 4
- Using FileSystem.SYSTEM.listRecursively() on MacOS, it returns incorrect directory name. HOT 3
- Update multiplatform example docs for file system HOT 1
- Gitt
- Add zip file support on non-JVM targets. HOT 3
- Pipe.fold: destination sink can remain open even after pipe closed HOT 2
- The compatibility issue with TarArchiveOutputStream
- Github lives
- ZipFileSystem should expose more metadata HOT 1
- Add `COpaquePointer.readByteString(Long)` helper
- Consider `ignoreWhitespace=true` parameter to `decodeHex` HOT 1
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.