Rewrite file systems to use ByteChannels#575
Open
SquidDev wants to merge 4 commits intodan200:masterfrom
Open
Conversation
This replaces the existing IMount openFor* method with openChannelFor* ones, which return an appropriate byte channel instead. As channels are not correctly closed when GCed, we introduce a FileSystemWrapper. We store a weak reference to this, and when it is GCed or the file closed, we will remove it from our "open file" set and ensure any underlying buffers are closed. While this change may seem a little odd, it does introduce some benefits: - We can replace JarMount with a more general FileSystemMount. This does assume a read-only file system, but could technically be used for other sources. - Add support for seekable (binary) handles. We can now look for instances of SeekableByteChannel and dynamically add it. This works for all binary filesystem and HTTP streams. - Rewrite the io library to more accurately emulate PUC Lua's implementation. We do not correctly implement some elements (most noticably "*n", but it's a definite improvement.
d6c5631 to
518eefb
Compare
- Rename openStreamFor* methods to more accurate openChannelFor* - Fix ArrayByteChannel having an incorrect .position() implementation
- Fix stdin not being considered a "readable" input - Return an unsigned byte rather than a signed one for no-args .read()
Contributor
Author
|
Possibly worth noting that seekable binary handles do not work for Jar mounts - namely the It would be possible to implement this by reading the entire contents of the file into memory and exposing it as an |
ccserver
pushed a commit
to ccserver/ComputerCraft
that referenced
this pull request
Sep 16, 2019
…file-seeking Rewrite file systems to use ByteChannels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This replaces the existing
IMountopenFor*method withopenChannelFor*ones, which return an appropriate byte channel instead. I've put a little more detail in the commit message about the implications of this, but there's a couple of user-facing benefits:os.dateandsetvbuf, neither of which are implemented.