You really should read the help before you write stuff.

From the help file...
The -n switch allows you to read a $crlf terminated line into a &binvar. If the incoming line does not contain a $crlf, no bytes will be read into &binvar, unless you specify the -f switch, which forces the read (same as when reading into %vars).

So adding a -n to the "sockread %a" is insane since its not a binary var
And adding a -f to either of the "sockread &a" is pointless since it has no -n and shouldnt have one anyway, since the data isnt textual but binary, so you just want to take what there is/what you can take and write it to file.

The code is even written to save processing time by doing repeating sockreads untill the buffer is empty instead of relying on repeated event calls.