-
-
Notifications
You must be signed in to change notification settings - Fork 11
FILE protocol example
The file:
protocol is a URI scheme for reading and writing files on the local system. libcURL supports this protocol even though it's not really a network protocol at all.
This example performs a synchronous file read on the calling thread.
Dim curl As New cURLClient
Dim file As FolderItem = SpecialFolder.Desktop.Child("test.txt")
If curl.Get(file.URLPath) Then
Dim data As String = curl.GetDownloadedData()
Else
MsgBox(libcURL.FormatError(curl.LastError))
End If
This example performs an asynchronous file read in a console application, and prints the output directly to the screen. The Get
method accepts an optional Writeable
object to which downloaded data should be written. Because this is a console application an event loop must be supplied for the asynchronous transfers to run on:
Dim curl As New cURLClient
Dim file As FolderItem = SpecialFolder.Desktop.Child("test.txt")
curl.Get(file.URLPath, stdout) ' stdout implements Writeable
Do
App.DoEvents() ' async transfers require an event loop!
Loop Until curl.IsTransferComplete
If curl.LastError <> 0 Then
Print("curl error: " + Str(curl.LastError))
End If
This example performs a synchronous file write on the calling thread.
Dim curl As New cURLClient
Dim file As FolderItem = SpecialFolder.Desktop.Child("test.txt")
If Not curl.Put(file.URLPath, "Hello, world!") Then
MsgBox(libcURL.FormatError(curl.LastError))
End If
This example performs an asynchronous file write in a console application. Because this is a console application an event loop must be supplied for the asynchronous transfers to run on:
Dim curl As New cURLClient
Dim file As FolderItem = SpecialFolder.Desktop.Child("test.txt")
curl.Put(file.URLPath, "Hello, world!")
Do
App.DoEvents() ' async transfers require an event loop!
Loop Until curl.IsTransferComplete
If curl.LastError <> 0 Then
Print("curl error: " + Str(curl.LastError))
End If
Wiki home | Project page | Bugs | Become a sponsor
Text and code examples are Copyright ©2014-24 Andrew Lambert, offered under the CC BY-SA 3.0 License.