-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add FileAccess.set_length(new_length)
to truncate existing files
#6776
Comments
I'm not sure how common this is in lower level details, or the way truncation of files is supported in various platforms other than copying the data There's no way to do this as far as I know in the standard c++ library for example |
Really? C++ standard library is just an abstraction and a wrapper to OS calls. Other abstractions have this. On C# there is FileStream.SetLength(). On Windows it seems to call Kernel32.dll. On Linux I believe it calls ftruncate? |
Godot is not limited to standard C++ file API, it's already relaying on
|
FileAccess.set_length(new_length)
to truncate existing files
How does this compare to opening a file, reading its first N bytes and saving that over the existing file? I assume a |
@bruvzg I am aware that's why I said "for example" as I was unsure how cross platform supported this was for an open file |
|
i think this is pretty valuable because the handle never gets closed - which is useful for text editors which may want to prevent the file from being deleted from under the engine's nose |
Implemented by godotengine/godot#90403. |
Describe the project you are working on
Modifying existing files, such as game state, cannot be shortened.
I cannot truncate file.
Describe the problem or limitation you are having in your project
File can be enlarged by writing new content, but cannot be shortened.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Add FileAccess.set_length()
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Calls OS IO function that shortens file size.
If this enhancement will not be used often, can it be worked around with a few lines of script?
Not that I know of.
Is there a reason why this should be core and not an add-on in the asset library?
Basic necessity low-level IO function.
The text was updated successfully, but these errors were encountered: