Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/io/file_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ String FileAccess::fix_path(const String &p_path) const {
return r_path;
}

void FileAccess::advance(int64_t p_offset) {
seek(get_position() + p_offset);
}

/* these are all implemented for ease of porting, then can later be optimized */
uint8_t FileAccess::get_8() const {
uint8_t data = 0;
Expand Down Expand Up @@ -966,6 +970,7 @@ void FileAccess::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_path"), &FileAccess::get_path);
ClassDB::bind_method(D_METHOD("get_path_absolute"), &FileAccess::get_path_absolute);
ClassDB::bind_method(D_METHOD("is_open"), &FileAccess::is_open);
ClassDB::bind_method(D_METHOD("advance", "offset"), &FileAccess::advance);
ClassDB::bind_method(D_METHOD("seek", "position"), &FileAccess::seek);
ClassDB::bind_method(D_METHOD("seek_end", "position"), &FileAccess::seek_end, DEFVAL(0));
ClassDB::bind_method(D_METHOD("get_position"), &FileAccess::get_position);
Expand Down
1 change: 1 addition & 0 deletions core/io/file_access.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class FileAccess : public RefCounted {
virtual String get_path() const { return ""; } /// returns the path for the current open file
virtual String get_path_absolute() const { return ""; } /// returns the absolute path for the current open file

void advance(int64_t p_offset); ///< advance a specific amount of bytes
virtual void seek(uint64_t p_position) = 0; ///< seek to a given position
virtual void seek_end(int64_t p_position = 0) = 0; ///< seek from the end of file with negative offset
virtual uint64_t get_position() const = 0; ///< get position in the file
Expand Down
7 changes: 7 additions & 0 deletions doc/classes/FileAccess.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
<link title="3D Voxel Demo">https://godotengine.org/asset-library/asset/2755</link>
</tutorials>
<methods>
<method name="advance">
<return type="void" />
<param index="0" name="offset" type="int" />
<description>
Shifts the file reading/writing cursor by the specified offset (in bytes from the cursor's current position).
</description>
</method>
<method name="close">
<return type="void" />
<description>
Expand Down