16
What's New / Re: ScriptBasic Core Windows 32 bit - cURL
« on: May 25, 2021, 03:25:19 PM »
This example uses the cURL extension module to download the text version of the War and Peace book.
C:\sb_build\examples>sbc curl_wget.sb
http://www.textfiles.com/etext/FICTION/warpeace.txt
Data downloaded: 4434670 bytes.
Total download time: 1.672 sec.
Average download speed: 2590.150 kbyte/sec.
C:\sb_build\examples>
Code: Script BASIC
- 'cURL Example - Download War & Peace book as text file.
- IMPORT curl.sbi
- ch = curl::init()
- curl::option(ch, "URL", "http://www.textfiles.com/etext/FICTION/warpeace.txt")
- curl::option(ch, "FILE", "warpeace.txt")
- curl::perform(ch)
- PRINT curl::info(ch, "EFFECTIVE_URL"),"\n"
- PRINT FORMAT("Data downloaded: %0.0f bytes.\n", curl::info(ch, "SIZE_DOWNLOAD"))
- PRINT FORMAT("Total download time: %0.3f sec.\n", curl::info(ch, "TOTAL_TIME"))
- PRINT FORMAT("Average download speed: %0.3f kbyte/sec.\n", curl::info(ch, "SPEED_DOWNLOAD") / 1024)
- curl::finish(ch)
C:\sb_build\examples>sbc curl_wget.sb
http://www.textfiles.com/etext/FICTION/warpeace.txt
Data downloaded: 4434670 bytes.
Total download time: 1.672 sec.
Average download speed: 2590.150 kbyte/sec.
C:\sb_build\examples>