Byte per byte download is slow!

Blitz3D Forums/Blitz3D Programming/Byte per byte download is slow!

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

readbytes and writebytes seems to be for banks only or i didnt understand your idea correctly...

my code is based on BlitzGet:

Graphics 640, 480, 32, 2
SetBuffer BackBuffer()

DeleteFile "1_google_logo.jpg"
BlitzGet("http://www.tgdaily.com/picturegalleries/20070423/1_google_logo.jpg")
If FileType("1_google_logo.jpg") <> 1 Then RuntimeError "Download error!"

DrawImage LoadImage("1_google_logo.jpg"), 0, 0
Flip
WaitKey()
End

Function BlitzGet(path$)
If Left(path$, 7) = "http://" Then path$ = Right(path$, Len(path$) - 7)
inst = Instr(path$, "/")
If inst Then
	host$ = Left(path$, inst - 1)
	path$ = Right(path$, Len(path$) - inst + 1)
Else
	host$ = path$
	path$ = "/"
EndIf

If out$ = "" Then
	If path = "/" Then
		out$ = "Unknown file.txt"
	Else
		For findSlash = Len(path$) To 1 Step - 1
			testForSlash$ = Mid(path$, findSlash, 1)
			If testForSlash$ = "/" Then
				out$ = Right(path$, Len(path$) - findSlash)
				Exit
			EndIf
		Next
		If out$ = "" Then out$ = "Unknown file.txt"
	EndIf
EndIf

tcp = OpenTCPStream(host$, 80)
If tcp Then
	WriteLine tcp, "GET " + path$ + " HTTP/1.1"
	WriteLine tcp, "Host: " + host$
	WriteLine tcp, "User-Agent: unknown"
	WriteLine tcp, "Accept: */*"
	WriteLine tcp, ""
	Repeat
		header$ = ReadLine(tcp)
		reply$ = ""
		inst = Instr(header$, ": ")
		If inst Then reply$ = Left(header$, inst + 1)
		If Lower(reply$) = "content-length: " Then toread = Right(header$, Len(header$) - Len(reply$))
	Until header$ = "" Or Eof(tcp)
	If toread > 0 Then
		file = WriteFile(out$)
		For readpath = 1 To toread
			;==========================================================================================
			If Eof(tcp) = False Then WriteByte file, ReadByte(tcp)
			;==========================================================================================
		Next
		CloseFile file
		If readpath - 1 <> toread Then RuntimeError "Download failed!"
	EndIf
	CloseTCPStream tcp
Else
	RuntimeError "Failed to connect"
EndIf
End Function


I also tried reading and writing integers (=4 bytes) instead of bytes, which is WAY FASTER, but it adds 0-3 empty bytes at the end of the file which i dont really like to see...