user27703: This is a follow up question to How to speed up writing a file to a WifiClient?
I modified the old code to read from one Stream and write to another which looked like this and worked fine albite being a bit slow
while (file.available() > 0)
{
    client.print((char)file.read());
}
client.flush();

to use a buffer, like so
char buffer[300];
size_t bufferSize = sizeof(buffer);

// ...

while (file.available() > 0)
{   
    memset(buffer, 0, bufferSize);  
    file.read(buffer, bufferSize);

    client.print(buffer);
}
client.flush();

Now, if the buffer size is > 15 (in the above case, it's 300), two additional characters Øb are introduced after the buffer size amount of characters. If the buffer size is <= 15, this does not happen.
If the file to be read contains abcdefg repeated several times, I get the following result for a buffer size of 32:
|-------- 32 characters -------|Øb|-------- 32 characters -------|Øb|-----
abcdefgabcdefgabcdefgabcdefgabcdØbefgabcdefgabcdefgabcdefgabcdefgaØbbcdefg

What's causing those additional characters to appear?
The above output is produced in the browser If I do not specify a charset. if I do, I get � instead of Øb.

user4143: Try recording the actual number of bytes read and only write that number of bytes:
size_t nr = file.read(buffer, bufferSize);
client.write(buffer, nr);


27703: <p>This is a follow up question to <a href="https://arduino.stackexchange.com/q/30558/27703">How to speed up writing a file to a WifiClient?</a></p>

<p>I modified the old code to read from one <code>Stream</code> and write to another which looked like this and worked fine albite being a bit slow</p>

<pre><code>while (file.available() &gt; 0)
{
    client.print((char)file.read());
}
client.flush();
</code></pre>

<p>to use a buffer, like so</p>

<pre><code>char buffer[300];
size_t bufferSize = sizeof(buffer);

// ...

while (file.available() &gt; 0)
{   
    memset(buffer, 0, bufferSize);  
    file.read(buffer, bufferSize);

    client.print(buffer);
}
client.flush();
</code></pre>

<p>Now, if the buffer size is > 15 (in the above case, it's 300), two additional characters <code>Øb</code> are introduced after the buffer size amount of characters. <strong>If the buffer size is &lt;= 15, this does not happen.</strong></p>

<p>If the file to be read contains <code>abcdefg</code> repeated several times, I get the following result for a buffer size of 32:</p>

<pre><code>|-------- 32 characters -------|Øb|-------- 32 characters -------|Øb|-----
abcdefgabcdefgabcdefgabcdefgabcdØbefgabcdefgabcdefgabcdefgabcdefgaØbbcdefg
</code></pre>

<p><strong>What's causing those additional characters to appear?</strong></p>

<p>The above output is produced in the browser If I do <strong>not</strong> specify a charset. if I do, I get <code>�</code> instead of <code>Øb</code>.</p>
 4143: <p>Try recording the actual number of bytes read and only write that number of bytes:</p>

<pre><code>size_t nr = file.read(buffer, bufferSize);
client.write(buffer, nr);
</code></pre>
