I was hoping to send a file across the network by reading it in byte by byte, sending it as a string of perhaps 4K at at time, then writing it back to a file at the other side.
The problem is, there is no read by byte. I tried to be a bit creative but my logic is flawed:
1. Read file as integers (4 bytes)
2a. Reduce integer to 2 x 2-byte values and push them to a string using CHR()
2b. Reduce integer to 4 x 1-byte values and push them to a string using CHR()
3. Write string to file (as a test, omitting network for now)
Here's the code for the 4 x 1-byte attempt:
for n = 1 to size step 4
if n < size - 3
count = count + 1
i[count] = readInteger(f)
endif
if count = 1024
myStr$ = ""
for x = 1 to 1024
valf# = i[x] / 1000.0
val1 = trunc(valf#)
valf# = i[x] / 100.0
val2 = trunc(valf#) - (val1 * 10)
valf# = i[x] / 10.0
val3 = trunc(valf#) - (val1 * 100) - (val2 * 10)
val4 = i[x] - (val1 * 1000) - (val2 * 100) - (val3 * 10)
myStr$ = myStr$ + chr(val1) + chr(val2) + chr(val3) + chr(val4)
next x
writeString(f2,myStr$)
count = 0
endif
next n
This doesn't take account of the final few bytes, but other than that I get a file of the same size (tested using a 630KB image file). However, the content of the file is completely corrupted.
Any ideas on how to achieve this challenge without a HTTP server?