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)
- Question: How do I access FileSystem in wasmJs? HOT 3
- API for File Locking
- API for unwrapping FileSystem HOT 2
- Extension mechanism for FileSystem HOT 4
- Path.relativeTo does not respect 'current directory dot'
- Windows (native build) codepage issues HOT 4
- 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
- zero-copy ByteArray to Buffer for reading purpose HOT 6
- Optimize `AsyncTimeout` operations.
- Release compatible with Kotlin 2.0 HOT 8
- How to convert from byteArray into file
- `AwaitSignalTest.signaled` is flaky
- `SocketTimeoutTest.writeWithTimeout` is flaky
- `PipeKotlinTest.honorsUnderlyingSinkDeadlineOnFlushingWhenItIsSmaller` is flaky
- Segment previous/next is itself 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.