Change file reading from byte arrays to streams #11
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-SvenGDK/UFS2Tool!11
Loading…
Reference in a new issue
No description provided.
Delete branch "Nielk1/enhancement-read_file_as_stream"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This change is a big one.
The current logic loads an entire file into memory before processing it. On it's own this is fine for a simple tool, but the problem comes with files larger than Int32.MaxValue, due to how C# handles arrays. I ran into files with this problem.
The new logic uses streams whenever possible. It makes some pretty large changes to the data block traversal so this will need review.
Tests have also been altered to use the new stream based read after the old but renamed byte array based read. The tests use a new construct, a ValidationWriteStream, which is a crude fake stream formed around a byte array that will Assert if the bytes received do not match the underlying array, overflow the length of the underlying array, or if the
AssertCompletefunction is called do not visit all array indexes.These changes were made for my own purposes where I needed to extract large files from a UFS1 image but I hope they help here too.
Note that Dokany logic was not tested, so be sure to review that. It was adjusted to use streams and offsets so requests to read parts of files wouldn't need to load the entire file into memory first. Writing is still restricted to the old ways so this only fixes (but untested) reading large files.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.