<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/Modules/FileSystem/file/readShort?action=history&amp;feed=atom</id>
	<title>Modules/FileSystem/file/readShort - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/Modules/FileSystem/file/readShort?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Modules/FileSystem/file/readShort&amp;action=history"/>
	<updated>2026-04-06T20:32:26Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=Modules/FileSystem/file/readShort&amp;diff=73735&amp;oldid=prev</id>
		<title>Danilo at 03:01, 23 January 2022</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Modules/FileSystem/file/readShort&amp;diff=73735&amp;oldid=prev"/>
		<updated>2022-01-23T03:01:07Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 03:01, 23 January 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;pageclass class=&quot;#3cc882&quot; subcaption=&quot;File function&quot;&gt;&amp;lt;/pageclass&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;__NOTOC__&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;__NOTOC__&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This function attempts to read a short (native type) from a file and returns it. The amount of bytes read should be two.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This function attempts to read a short (native type) from a file and returns it. The amount of bytes read should be two.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki-wiki_dev_:diff::1.12:old-73651:rev-73735 --&gt;
&lt;/table&gt;</summary>
		<author><name>Danilo</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=Modules/FileSystem/file/readShort&amp;diff=73651&amp;oldid=prev</id>
		<title>Danilo: Created page with &quot;__NOTOC__ This function attempts to read a short (native type) from a file and returns it. The amount of bytes read should be two.  ==Syntax== &lt;syntaxhighlight lang=&quot;lua&quot;&gt; short file:readShort () &lt;/syntaxhighlight&gt;  ==Returns== Returns the short integer if it was successfully read from the file, '''false''' otherwise.  ==Example== &lt;section name=&quot;Client&quot; class=&quot;client&quot; show=&quot;true&quot;&gt; This snippet reads and writes string buffers into a custom file format. &lt;syntaxhighlight la...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Modules/FileSystem/file/readShort&amp;diff=73651&amp;oldid=prev"/>
		<updated>2022-01-19T03:31:16Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__NOTOC__ This function attempts to read a short (native type) from a file and returns it. The amount of bytes read should be two.  ==Syntax== &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt; short file:readShort () &amp;lt;/syntaxhighlight&amp;gt;  ==Returns== Returns the short integer if it was successfully read from the file, &amp;#039;&amp;#039;&amp;#039;false&amp;#039;&amp;#039;&amp;#039; otherwise.  ==Example== &amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt; This snippet reads and writes string buffers into a custom file format. &amp;lt;syntaxhighlight la...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__NOTOC__&lt;br /&gt;
This function attempts to read a short (native type) from a file and returns it. The amount of bytes read should be two.&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
short file:readShort ()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Returns==&lt;br /&gt;
Returns the short integer if it was successfully read from the file, '''false''' otherwise.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This snippet reads and writes string buffers into a custom file format.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local function writeBuffers( outFile, buffers )&lt;br /&gt;
    -- Write header information.&lt;br /&gt;
    outFile:writeInt( #buffers ); -- number of buffers&lt;br /&gt;
    &lt;br /&gt;
    -- Write the buffers.&lt;br /&gt;
    for m,n in ipairs( buffers ) do&lt;br /&gt;
        local bufferContent = tostring( n );&lt;br /&gt;
&lt;br /&gt;
        -- Write header of buffer.&lt;br /&gt;
        outFile:writeShort( #bufferContent ); -- length of buffer&lt;br /&gt;
&lt;br /&gt;
        -- Write the content&lt;br /&gt;
        outFile:write( bufferContent );&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function readBuffers( inFile )&lt;br /&gt;
    local buffers = {};&lt;br /&gt;
&lt;br /&gt;
    -- Read header information.&lt;br /&gt;
    local numBuffers = inFile:readInt();&lt;br /&gt;
&lt;br /&gt;
    -- Make sure we read the int correctly.&lt;br /&gt;
    -- Fails if the file has less than 4 bytes to read.&lt;br /&gt;
    if ( numBuffers ) then&lt;br /&gt;
        local n = 1;&lt;br /&gt;
&lt;br /&gt;
        while ( n &amp;lt;= numBuffers ) do&lt;br /&gt;
            -- Read buffer header.&lt;br /&gt;
            local bufferSize = inFile:readShort();&lt;br /&gt;
&lt;br /&gt;
            -- We always have to add the amount of buffers specified by the header.&lt;br /&gt;
            -- Hence we always add a buffer to the result array.&lt;br /&gt;
            local buffer = &amp;quot;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
            if ( bufferSize ) then&lt;br /&gt;
                -- Read the buffer.&lt;br /&gt;
                buffer = inFile:read( bufferSize );&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            -- Append the result buffer.&lt;br /&gt;
            buffers[n] = buffer;&lt;br /&gt;
&lt;br /&gt;
            n = n + 1;&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    return buffers;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Manager some buffers in a file.&lt;br /&gt;
local myBuffers = { &amp;quot;Hello World!&amp;quot;, &amp;quot;Cooking eggs on a frying pan&amp;quot;, &amp;quot;The American Pizzas taste awesome&amp;quot;, &amp;quot;There is no bathroom.&amp;quot; };&lt;br /&gt;
&lt;br /&gt;
local theFile = fileCreate( &amp;quot;buffers.dat&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
-- First write the buffers into the file.&lt;br /&gt;
writeBuffers( theFile, myBuffers );&lt;br /&gt;
&lt;br /&gt;
-- Now retrieve them again.&lt;br /&gt;
theFile:seek( 0, &amp;quot;set&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
myBuffers = readBuffers( theFile );&lt;br /&gt;
&lt;br /&gt;
-- Output the buffers.&lt;br /&gt;
for m,n in ipairs( myBuffers ) do&lt;br /&gt;
    outputChatBox( n );&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
{{:Modules/FileSystem/file/functions}}&lt;/div&gt;</summary>
		<author><name>Danilo</name></author>
	</entry>
</feed>