Skip to content
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

Rename File::get_len() get_length() #49061

Merged
merged 1 commit into from
May 25, 2021
Merged
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
8 changes: 4 additions & 4 deletions core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,9 +1272,9 @@ uint64_t _File::get_position() const {
return f->get_position();
}

uint64_t _File::get_len() const {
uint64_t _File::get_length() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
return f->get_len();
return f->get_length();
}

bool _File::eof_reached() const {
Expand Down Expand Up @@ -1536,7 +1536,7 @@ void _File::_bind_methods() {
ClassDB::bind_method(D_METHOD("seek", "position"), &_File::seek);
ClassDB::bind_method(D_METHOD("seek_end", "position"), &_File::seek_end, DEFVAL(0));
ClassDB::bind_method(D_METHOD("get_position"), &_File::get_position);
ClassDB::bind_method(D_METHOD("get_len"), &_File::get_len);
ClassDB::bind_method(D_METHOD("get_length"), &_File::get_length);
ClassDB::bind_method(D_METHOD("eof_reached"), &_File::eof_reached);
ClassDB::bind_method(D_METHOD("get_8"), &_File::get_8);
ClassDB::bind_method(D_METHOD("get_16"), &_File::get_16);
Expand All @@ -1545,7 +1545,7 @@ void _File::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_float"), &_File::get_float);
ClassDB::bind_method(D_METHOD("get_double"), &_File::get_double);
ClassDB::bind_method(D_METHOD("get_real"), &_File::get_real);
ClassDB::bind_method(D_METHOD("get_buffer", "len"), &_File::get_buffer);
ClassDB::bind_method(D_METHOD("get_buffer", "length"), &_File::get_buffer);
ClassDB::bind_method(D_METHOD("get_line"), &_File::get_line);
ClassDB::bind_method(D_METHOD("get_csv_line", "delim"), &_File::get_csv_line, DEFVAL(","));
ClassDB::bind_method(D_METHOD("get_as_text"), &_File::get_as_text);
Expand Down
2 changes: 1 addition & 1 deletion core/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class _File : public Reference {
void seek(int64_t p_position); // Seek to a given position.
void seek_end(int64_t p_position = 0); // Seek from the end of file.
uint64_t get_position() const; // Get position in the file.
uint64_t get_len() const; // Get size of the file.
uint64_t get_length() const; // Get size of the file.

bool eof_reached() const; // Reading passed EOF.

Expand Down
2 changes: 1 addition & 1 deletion core/io/file_access_compressed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ uint64_t FileAccessCompressed::get_position() const {
}
}

uint64_t FileAccessCompressed::get_len() const {
uint64_t FileAccessCompressed::get_length() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
if (writing) {
return write_max;
Expand Down
2 changes: 1 addition & 1 deletion core/io/file_access_compressed.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class FileAccessCompressed : public FileAccess {
virtual void seek(uint64_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
virtual uint64_t get_position() const; ///< get position in the file
virtual uint64_t get_len() const; ///< get size of the file
virtual uint64_t get_length() const; ///< get size of the file

virtual bool eof_reached() const; ///< reading passed EOF

Expand Down
22 changes: 11 additions & 11 deletions core/io/file_access_encrypted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
}

base = p_base->get_position();
ERR_FAIL_COND_V(p_base->get_len() < base + length, ERR_FILE_CORRUPT);
ERR_FAIL_COND_V(p_base->get_length() < base + length, ERR_FILE_CORRUPT);
uint64_t ds = length;
if (ds % 16) {
ds += 16 - (ds % 16);
Expand Down Expand Up @@ -199,23 +199,23 @@ String FileAccessEncrypted::get_path_absolute() const {
}

void FileAccessEncrypted::seek(uint64_t p_position) {
if (p_position > get_len()) {
p_position = get_len();
if (p_position > get_length()) {
p_position = get_length();
}

pos = p_position;
eofed = false;
}

void FileAccessEncrypted::seek_end(int64_t p_position) {
seek(get_len() + p_position);
seek(get_length() + p_position);
}

uint64_t FileAccessEncrypted::get_position() const {
return pos;
}

uint64_t FileAccessEncrypted::get_len() const {
uint64_t FileAccessEncrypted::get_length() const {
return data.size();
}

Expand All @@ -225,7 +225,7 @@ bool FileAccessEncrypted::eof_reached() const {

uint8_t FileAccessEncrypted::get_8() const {
ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode.");
if (pos >= get_len()) {
if (pos >= get_length()) {
eofed = true;
return 0;
}
Expand All @@ -239,7 +239,7 @@ uint64_t FileAccessEncrypted::get_buffer(uint8_t *p_dst, uint64_t p_length) cons
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
ERR_FAIL_COND_V_MSG(writing, -1, "File has not been opened in read mode.");

uint64_t to_copy = MIN(p_length, get_len() - pos);
uint64_t to_copy = MIN(p_length, get_length() - pos);
for (uint64_t i = 0; i < to_copy; i++) {
p_dst[i] = data[pos++];
}
Expand All @@ -258,11 +258,11 @@ Error FileAccessEncrypted::get_error() const {
void FileAccessEncrypted::store_buffer(const uint8_t *p_src, uint64_t p_length) {
ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");

if (pos < get_len()) {
if (pos < get_length()) {
for (uint64_t i = 0; i < p_length; i++) {
store_8(p_src[i]);
}
} else if (pos == get_len()) {
} else if (pos == get_length()) {
data.resize(pos + p_length);
for (uint64_t i = 0; i < p_length; i++) {
data.write[pos + i] = p_src[i];
Expand All @@ -280,10 +280,10 @@ void FileAccessEncrypted::flush() {
void FileAccessEncrypted::store_8(uint8_t p_dest) {
ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");

if (pos < get_len()) {
if (pos < get_length()) {
data.write[pos] = p_dest;
pos++;
} else if (pos == get_len()) {
} else if (pos == get_length()) {
data.push_back(p_dest);
pos++;
}
Expand Down
2 changes: 1 addition & 1 deletion core/io/file_access_encrypted.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class FileAccessEncrypted : public FileAccess {
virtual void seek(uint64_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
virtual uint64_t get_position() const; ///< get position in the file
virtual uint64_t get_len() const; ///< get size of the file
virtual uint64_t get_length() const; ///< get size of the file

virtual bool eof_reached() const; ///< reading passed EOF

Expand Down
2 changes: 1 addition & 1 deletion core/io/file_access_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ uint64_t FileAccessMemory::get_position() const {
return pos;
}

uint64_t FileAccessMemory::get_len() const {
uint64_t FileAccessMemory::get_length() const {
ERR_FAIL_COND_V(!data, 0);
return length;
}
Expand Down
2 changes: 1 addition & 1 deletion core/io/file_access_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class FileAccessMemory : public FileAccess {
virtual void seek(uint64_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position); ///< seek from the end of file
virtual uint64_t get_position() const; ///< get position in the file
virtual uint64_t get_len() const; ///< get size of the file
virtual uint64_t get_length() const; ///< get size of the file

virtual bool eof_reached() const; ///< reading passed EOF

Expand Down
2 changes: 1 addition & 1 deletion core/io/file_access_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ uint64_t FileAccessNetwork::get_position() const {
return pos;
}

uint64_t FileAccessNetwork::get_len() const {
uint64_t FileAccessNetwork::get_length() const {
ERR_FAIL_COND_V_MSG(!opened, 0, "File must be opened before use.");
return total_size;
}
Expand Down
2 changes: 1 addition & 1 deletion core/io/file_access_network.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class FileAccessNetwork : public FileAccess {
virtual void seek(uint64_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
virtual uint64_t get_position() const; ///< get position in the file
virtual uint64_t get_len() const; ///< get size of the file
virtual uint64_t get_length() const; ///< get size of the file

virtual bool eof_reached() const; ///< reading passed EOF

Expand Down
2 changes: 1 addition & 1 deletion core/io/file_access_pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ uint64_t FileAccessPack::get_position() const {
return pos;
}

uint64_t FileAccessPack::get_len() const {
uint64_t FileAccessPack::get_length() const {
return pf.size;
}

Expand Down
2 changes: 1 addition & 1 deletion core/io/file_access_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class FileAccessPack : public FileAccess {
virtual void seek(uint64_t p_position);
virtual void seek_end(int64_t p_position = 0);
virtual uint64_t get_position() const;
virtual uint64_t get_len() const;
virtual uint64_t get_length() const;

virtual bool eof_reached() const;

Expand Down
6 changes: 3 additions & 3 deletions core/io/file_access_zip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
pos = f->get_position() + offset;
break;
case ZLIB_FILEFUNC_SEEK_END:
pos = f->get_len() + offset;
pos = f->get_length() + offset;
break;
default:
break;
Expand Down Expand Up @@ -270,15 +270,15 @@ void FileAccessZip::seek(uint64_t p_position) {

void FileAccessZip::seek_end(int64_t p_position) {
ERR_FAIL_COND(!zfile);
unzSeekCurrentFile(zfile, get_len() + p_position);
unzSeekCurrentFile(zfile, get_length() + p_position);
}

uint64_t FileAccessZip::get_position() const {
ERR_FAIL_COND_V(!zfile, 0);
return unztell(zfile);
}

uint64_t FileAccessZip::get_len() const {
uint64_t FileAccessZip::get_length() const {
ERR_FAIL_COND_V(!zfile, 0);
return file_info.uncompressed_size;
}
Expand Down
2 changes: 1 addition & 1 deletion core/io/file_access_zip.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class FileAccessZip : public FileAccess {
virtual void seek(uint64_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
virtual uint64_t get_position() const; ///< get position in the file
virtual uint64_t get_len() const; ///< get size of the file
virtual uint64_t get_length() const; ///< get size of the file

virtual bool eof_reached() const; ///< reading passed EOF

Expand Down
2 changes: 1 addition & 1 deletion core/io/pck_packer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Error PCKPacker::add_file(const String &p_file, const String &p_src, bool p_encr
pf.path = p_file;
pf.src_path = p_src;
pf.ofs = ofs;
pf.size = f->get_len();
pf.size = f->get_length();

Vector<uint8_t> data = FileAccess::get_file_as_array(p_src);
{
Expand Down
2 changes: 1 addition & 1 deletion core/io/xml_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ Error XMLParser::open(const String &p_path) {

ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot open file '" + p_path + "'.");

length = file->get_len();
length = file->get_length();
ERR_FAIL_COND_V(length < 1, ERR_FILE_CORRUPT);

if (data) {
Expand Down
2 changes: 1 addition & 1 deletion core/io/zip_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
pos = f->get_position() + offset;
break;
case ZLIB_FILEFUNC_SEEK_END:
pos = f->get_len() + offset;
pos = f->get_length() + offset;
break;
default:
break;
Expand Down
4 changes: 2 additions & 2 deletions core/os/file_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ uint64_t FileAccess::get_buffer(uint8_t *p_dst, uint64_t p_length) const {

String FileAccess::get_as_utf8_string() const {
Vector<uint8_t> sourcef;
uint64_t len = get_len();
uint64_t len = get_length();
sourcef.resize(len + 1);

uint8_t *w = sourcef.ptrw();
Expand Down Expand Up @@ -565,7 +565,7 @@ Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path, Error *r_err
ERR_FAIL_V_MSG(Vector<uint8_t>(), "Can't open file from path '" + String(p_path) + "'.");
}
Vector<uint8_t> data;
data.resize(f->get_len());
data.resize(f->get_length());
f->get_buffer(data.ptrw(), data.size());
memdelete(f);
return data;
Expand Down
2 changes: 1 addition & 1 deletion core/os/file_access.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class FileAccess {
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
virtual uint64_t get_len() const = 0; ///< get size of the file
virtual uint64_t get_length() const = 0; ///< get size of the file

virtual bool eof_reached() const = 0; ///< reading passed EOF

Expand Down
8 changes: 4 additions & 4 deletions doc/classes/File.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</return>
<description>
Returns [code]true[/code] if the file cursor has read past the end of the file.
[b]Note:[/b] This function will still return [code]false[/code] while at the end of the file and only activates when reading past it. This can be confusing but it conforms to how low-level file access works in all operating systems. There is always [method get_len] and [method get_position] to implement a custom logic.
[b]Note:[/b] This function will still return [code]false[/code] while at the end of the file and only activates when reading past it. This can be confusing but it conforms to how low-level file access works in all operating systems. There is always [method get_length] and [method get_position] to implement a custom logic.
</description>
</method>
<method name="file_exists" qualifiers="const">
Expand Down Expand Up @@ -121,10 +121,10 @@
<method name="get_buffer" qualifiers="const">
<return type="PackedByteArray">
</return>
<argument index="0" name="len" type="int">
<argument index="0" name="length" type="int">
</argument>
<description>
Returns next [code]len[/code] bytes of the file as a [PackedByteArray].
Returns next [code]length[/code] bytes of the file as a [PackedByteArray].
</description>
</method>
<method name="get_csv_line" qualifiers="const">
Expand Down Expand Up @@ -158,7 +158,7 @@
Returns the next 32 bits from the file as a floating-point number.
</description>
</method>
<method name="get_len" qualifiers="const">
<method name="get_length" qualifiers="const">
<return type="int">
</return>
<description>
Expand Down
2 changes: 1 addition & 1 deletion drivers/png/image_loader_png.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <string.h>

Error ImageLoaderPNG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) {
const uint64_t buffer_size = f->get_len();
const uint64_t buffer_size = f->get_length();
Vector<uint8_t> file_buffer;
Error err = file_buffer.resize(buffer_size);
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/unix/file_access_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ uint64_t FileAccessUnix::get_position() const {
return pos;
}

uint64_t FileAccessUnix::get_len() const {
uint64_t FileAccessUnix::get_length() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");

int64_t pos = ftello(f);
Expand Down
2 changes: 1 addition & 1 deletion drivers/unix/file_access_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class FileAccessUnix : public FileAccess {
virtual void seek(uint64_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
virtual uint64_t get_position() const; ///< get position in the file
virtual uint64_t get_len() const; ///< get size of the file
virtual uint64_t get_length() const; ///< get size of the file

virtual bool eof_reached() const; ///< reading passed EOF

Expand Down
2 changes: 1 addition & 1 deletion drivers/windows/file_access_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ uint64_t FileAccessWindows::get_position() const {
return aux_position;
}

uint64_t FileAccessWindows::get_len() const {
uint64_t FileAccessWindows::get_length() const {
ERR_FAIL_COND_V(!f, 0);

uint64_t pos = get_position();
Expand Down
2 changes: 1 addition & 1 deletion drivers/windows/file_access_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class FileAccessWindows : public FileAccess {
virtual void seek(uint64_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
virtual uint64_t get_position() const; ///< get position in the file
virtual uint64_t get_len() const; ///< get size of the file
virtual uint64_t get_length() const; ///< get size of the file

virtual bool eof_reached() const; ///< reading passed EOF

Expand Down
2 changes: 1 addition & 1 deletion editor/fileserver/editor_file_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void EditorFileServer::_subthread_start(void *s) {
cd->connection->put_data(buf4, 4);
encode_uint32(OK, buf4);
cd->connection->put_data(buf4, 4);
encode_uint64(fa->get_len(), buf4);
encode_uint64(fa->get_length(), buf4);
cd->connection->put_data(buf4, 8);

cd->files[id] = fa;
Expand Down
2 changes: 1 addition & 1 deletion editor/import/resource_importer_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Error ResourceImporterImage::import(const String &p_source_file, const String &p

ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot open file from path '" + p_source_file + "'.");

uint64_t len = f->get_len();
uint64_t len = f->get_length();

Vector<uint8_t> data;
data.resize(len);
Expand Down
2 changes: 1 addition & 1 deletion modules/bmp/image_loader_bmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Error ImageLoaderBMP::load_image(Ref<Image> p_image, FileAccess *f,

// A valid bmp file should always at least have a
// file header and a minimal info header
if (f->get_len() > BITMAP_FILE_HEADER_SIZE + BITMAP_INFO_HEADER_MIN_SIZE) {
if (f->get_length() > BITMAP_FILE_HEADER_SIZE + BITMAP_INFO_HEADER_MIN_SIZE) {
// File Header
bmp_header.bmp_file_header.bmp_signature = f->get_16();
if (bmp_header.bmp_file_header.bmp_signature == BITMAP_SIGNATURE) {
Expand Down
Loading