sourcemod icon indicating copy to clipboard operation
sourcemod copied to clipboard

Implement File.Size

Open dragokas opened this issue 3 years ago • 1 comments

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

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

dragokas avatar Sep 07 '21 19:09 dragokas

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);

asherkin avatar Sep 08 '21 00:09 asherkin