alliedmodders / sourcemod

SourceMod - Source Engine Scripting and Administration
http://www.sourcemod.net/
974 stars 422 forks source link

Implement File.Size #1578

Open dragokas opened 3 years ago

dragokas commented 3 years ago

Can you add please .Size property to "File" methodmap?

Same as: https://sm.alliedmods.net/new-api/files/FileSize

asherkin commented 3 years ago

FileSize is a stat call rather than operating on an open file (which is why it takes a path string rather than a file handle), so I'm not sure it is the best fit for a File methodmap property, and it'll be more expensive than properties generally are. That said, we could probably use the already open FD to reduce the perf impact, and it looks like IBaseFileSystem has an equiv for that as well - so maybe that rather different implementation would be a good fit.

The other option of course is you can do the usual C seek/tell dance:

File test = OpenFile("test.txt", "r");
test.Seek(0, SEEK_END);
int size = test.Position;
test.Seek(0, SEEK_SET);