Download only part of a file with ReceiveHTTPMemory()?
Download only part of a file with ReceiveHTTPMemory()?
There's a large text file (1 MB) that I'm currently downloading with ReceiveHTTPMemory() but I really only need the first 1 KB of it. Downloading the entire 10 MB just to use Left() on the data is silly. The ReceiveHTTPMemory() command doesn't have a flag to stop downloading after X bytes, so how would I do that? Thanks.
Re: Download only part of a file with ReceiveHTTPMemory()?
ReceiveHTTPMemory() does not support header parameters, so use HTTPRequest() instead:
However, you must ensure that the server supports HTTP requests with ranges.
Code: Select all
NewMap header$()
header$("Range") = "bytes=0-1023"
request = HTTPRequest(#PB_HTTP_Get, "https://...", "", 0, header$())
If request
response$ = HTTPInfo(request, #PB_HTTP_Response)
Debug StringByteLength(response$, #PB_Ascii)
FinishHTTP(request)
Else
Debug "Error"
EndIf
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version

