Skip to content

Commit d722155

Browse files
committed
FileAccess: Advance method
1 parent 80a3d20 commit d722155

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

core/io/file_access.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ String FileAccess::fix_path(const String &p_path) const {
294294
return r_path;
295295
}
296296

297+
void FileAccess::advance(int64_t p_offset) {
298+
seek(get_position() + p_offset);
299+
}
300+
297301
/* these are all implemented for ease of porting, then can later be optimized */
298302
uint8_t FileAccess::get_8() const {
299303
uint8_t data = 0;
@@ -966,6 +970,7 @@ void FileAccess::_bind_methods() {
966970
ClassDB::bind_method(D_METHOD("get_path"), &FileAccess::get_path);
967971
ClassDB::bind_method(D_METHOD("get_path_absolute"), &FileAccess::get_path_absolute);
968972
ClassDB::bind_method(D_METHOD("is_open"), &FileAccess::is_open);
973+
ClassDB::bind_method(D_METHOD("advance", "offset"), &FileAccess::advance);
969974
ClassDB::bind_method(D_METHOD("seek", "position"), &FileAccess::seek);
970975
ClassDB::bind_method(D_METHOD("seek_end", "position"), &FileAccess::seek_end, DEFVAL(0));
971976
ClassDB::bind_method(D_METHOD("get_position"), &FileAccess::get_position);

core/io/file_access.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class FileAccess : public RefCounted {
163163
virtual String get_path() const { return ""; } /// returns the path for the current open file
164164
virtual String get_path_absolute() const { return ""; } /// returns the absolute path for the current open file
165165

166+
void advance(int64_t p_offset); ///< advance a specific amount of bytes
166167
virtual void seek(uint64_t p_position) = 0; ///< seek to a given position
167168
virtual void seek_end(int64_t p_position = 0) = 0; ///< seek from the end of file with negative offset
168169
virtual uint64_t get_position() const = 0; ///< get position in the file

doc/classes/FileAccess.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
<link title="3D Voxel Demo">https://godotengine.org/asset-library/asset/2755</link>
4343
</tutorials>
4444
<methods>
45+
<method name="advance">
46+
<return type="void" />
47+
<param index="0" name="offset" type="int" />
48+
<description>
49+
Shifts the file reading/writing cursor by the specified offset (in bytes from the cursor's current position).
50+
</description>
51+
</method>
4552
<method name="close">
4653
<return type="void" />
4754
<description>

0 commit comments

Comments
 (0)