MTA:Eir/FileSystem/file/size: Difference between revisions
Jump to navigation
Jump to search
(Created page with "__NOTOC__ This function returns the size of a specific file/stream from beginning to end. Not all streams have to support this operation. ==Syntax== <syntaxhighlight lang="lua"> int file.size ...") |
No edit summary |
||
Line 4: | Line 4: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
int file | int file:size () | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 24: | Line 24: | ||
-- The the whole content of the file into a string buffer. | -- The the whole content of the file into a string buffer. | ||
local content = theFile | local content = theFile:read( theFile:size() ); | ||
-- Clean up the file handle. | -- Clean up the file handle. | ||
theFile | theFile:destroy(); | ||
return content; | return content; | ||
end | end |
Latest revision as of 23:47, 16 January 2022
This function returns the size of a specific file/stream from beginning to end. Not all streams have to support this operation.
Syntax
int file:size ()
Returns
Returns the amount of bytes that this file/stream object is made of.
Example
Click to collapse [-]
ClientThis snippet returns the contents of a file in a string buffer.
local function fileGetContents( path ) -- Prevent a warning being output by checking for file existance first. if not ( fileExists( path ) ) then return false; end; -- Open the requested file. local theFile = fileOpen( path ); if not ( theFile ) then return false; end; -- The the whole content of the file into a string buffer. local content = theFile:read( theFile:size() ); -- Clean up the file handle. theFile:destroy(); return content; end