-
-
Notifications
You must be signed in to change notification settings - Fork 11
libcURL.EasyHandle.DataAvailable
#libcURL.EasyHandle.DataAvailable
##Event Signature
Event Function DataAvailable(NewData As MemoryBlock) As Integer##Parameters
| Name | Type | Comment |
|---|---|---|
| NewData | MemoryBlock | The data that is available. |
##Return value
The number of bytes successfully consumed which should be equal to the number of bytes provided. You may also return CURL_WRITEFUNC_PAUSE to consume no data and pause the download.
##Notes This event handles the CURLOPT_WRITEFUNCTION callback. It is raised by EasyHandle.WriteCallback. The new data is discarded once this event returns.
You must return the number of bytes that were successfully handled; if the number of bytes handled is different from the number of bytes provided then libcURL will assume that an error has occurred.
##A neat trick
On Linux and Mac OS X, you may optionally replace this callback with a file pointer which libcURL will automatically write downloaded data to. For example:
Function DownloadToFile(URL As String, ToFile As FolderItem) As Boolean
#If TargetWin32 Then
Return False
#endif
Dim curl As New libcURL.EasyHandle
Dim filestream As BinaryStream = BinaryStream.Create(ToFile)
Dim fstream As Integer = filestream.Handle(BinaryStream.HandleTypeFilePointer)
Call curl.SetOption(libcURL.Opts.WRITEDATA, fstream)
Call curl.SetOption(libcURL.Opts.WRITEFUNCTION, Nil)
If Not curl.Perform(URL) Then MsgBox(libcURL.FormatError(curl.LastError))
filestream.Close
Return True
End Function
Attempting to do this under Win32 will cause libcURL to crash hard.
##See also
Wiki home | Project page | Bugs | Become a sponsor
Text and code examples are Copyright ©2014-26 Andrew Lambert, offered under the CC BY-SA 3.0 License.