Garry's Mod Wiki

Revision Difference

File:Read#520221

<function name="Read" parent="File" type="classfunc">⤶ <args>⤶ <arg name="length" type="number">Reads the specified amount of chars.</arg>⤶ </args>⤶ <rets>⤶ <ret name="data" type="string"></ret>⤶ </rets>⤶ <description>Reads the specified amount of chars and returns them as a binary string.</description>⤶ <realm>Shared</realm>⤶ </function>⤶ ⤶ <example>⤶ <description>Adapted from extensions/file.lua</description>⤶ <code>⤶ function file.Read( filename, path )⤶ ⤶ if ( path == true ) then path = "GAME" end⤶ if ( path == nil || path == false ) then path = "DATA" end⤶ ⤶ local f = file.Open( filename, "rb", path )⤶ if ( !f ) then return end⤶ ⤶ local str = f:Read( f:Size() )⤶ ⤶ f:Close()⤶ ⤶ if ( !str ) then str = "" end⤶ return str⤶ ⤶ end⤶ </code>⤶ </example>