Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS CURL Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /CURL/CURLS threaded download
This example is the version from Sat, 27th Aug 2021.
Project "CURLS threaded download.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
Class Window1 Inherits Window
Control EditField1 Inherits TextArea
ControlInstance EditField1 Inherits TextArea
End Control
Control List Inherits ListBox
ControlInstance List Inherits ListBox
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
stopped=false
Run
End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action()
stopped=true
End EventHandler
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action()
for each t as DownloadThread in threads
List.cell(t.listindex, 0) = t.d.Message
next
End EventHandler
End Control
Protected Sub run()
dim s as string
dim lines(-1),line as string
dim w as DownloadThread
s=EditField1.text
s=ReplaceLineEndings(s,EndOfLine)
lines=Split(s,EndOfLine)
for each line in lines
line=trim(line)
if line<>"" then
List.AddRow line
w=new DownloadThread
w.url=line
w.listindex=List.LastIndex
w.run
threads.Append w
end if
next
End Sub
Property Protected Threads() As DownloadThread
Property stopped As boolean
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu5 = ""
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
MenuItem UntitledMenu4 = ""
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = ""
End MenuBar
Class App Inherits Application
End Class
Class DownloadCURL Inherits CURLSMBS
EventHandler Sub DebugMessage(infotype as integer, data as string, dataSize as Integer)
// shows debug stuff
// System.DebugLog str(infotype)+" "+data
End EventHandler
EventHandler Function Progress(dltotal as Int64, dlnow as Int64, ultotal as Int64, ulnow as Int64, percent as double) As boolean
if dltotal=0 then
Message = "Downloading..."
else
Message = "Downloading "+Format(dlnow/dltotal,"0%")
end if
// show in console
// System.DebugLog list.Cell(listindex,0)
// this may improve GUI responses
// app.DoEvents
Return Window1.stopped
End EventHandler
EventHandler Function Write(data as string, dataSize as Integer) As integer
// using stream allows us to handle more data than fits in memory
b.Write data
size = size + lenb(data)
Return lenb(Data)
End EventHandler
Property Message As string
Property b As binaryStream
Property done As Boolean
Property size As Int64
End Class
Class DownloadThread Inherits Thread
EventHandler Sub Run()
dim e as integer
dim s as string
dim f as FolderItem
dim b as BinaryStream
s=NthField(url,"/",CountFields(url,"/"))
f=SpecialFolder.Desktop.Child("CURL Test - "+s)
b=BinaryStream.Create(f, true)
d=new DownloadCURL
d.OptionURL=url
d.YieldTime=true
d.b=b
d.OptionVerbose=true
e=d.Perform
d.message = "Finished. "+Format(d.size/1024,"0")+" kilobytes"
done = true
End EventHandler
Property d As DownloadCURL
Property done As Boolean
Property listindex As integer
Property url As string
End Class
End Project
See also:
- /CURL/CURLS Amazon S3 download
- /CURL/CURLS headers
- /CURL/CURLS info
- /CURL/CURLS Low Level Sockets
- /CURL/CURLS picture download
- /CURL/CURLS pop3 email delete
- /CURL/CURLS post form values/CURLS post form values
- /CURL/CURLS post form/CURLS post form
- /CURL/CURLS preemptive threaded upload
- /CURL/CURLS resume download
The items on this page are in the following plugins: MBS CURL Plugin.