A downloading library for Love2d
First require the library LOVEDownloader = require('LOVEDownloader').
fileDown = LOVEDownloader.download( downloadURL, filename, callbacks ) returns you a FileDownload instance. Now you can start the download using fileDown:start(). If you don't give a filename, it will be saved in a string, that can be accessed with fileDown.content when finished. You have to call fileDown:update() to update all variables and call the callbacks.
LOVEDownloader = require('LOVEDownloader')
function love.load()
file = LOVEDownloader.download("http://www.randomnumber.org/randdata/1MB_200409232104.dat", "file.dat", {
update = function(per, down, size)
print(per, down, size)
end
})
file:start() -- Start download
end
function love.update()
file:update()
end
function love.draw()
love.graphics.print(math.floor(file.progress * 100) .. "%", 10, 10)
if file.success then
print("success")
end
endCreates a FileDown object.
- Arguments
- downloadURL: The URL to the File to download
- filename: The filename to save as. If not set it will be saved in a string, that can be accessed with
FileDown.contentwhen finished. - callbacks: A table with callback functions
- Returns
- A FileDown object.
Can be used in the table of the last argument in LOVEDownloader.download
Example
file = LOVEDownloader.download( "http://example.com/file.dat" , "file.dat", {
update = function(per, down, size)
print(per, down, size)
end
})Called when received update from download-thread.
- Arguments
- per: the progress of the download.
- down: the downloaded size in Bytes.
- size: the size of the file.
Called when got the content, if filename not set.
- Arguments
- content: the content of the downloaded file.
Called when download successed.
Callen when an error occurred.
- Arguments
- desc: The description of the error.
Called when download stopped with FileDown:stop()
Called when finished successfully, stopped or an error occurred.
Starts the Download.
Stops the Download.
Updates all variables.
The progress of the download. A number between 0 and 1.
A boolean value. true, if finished successfully.
Description of the error that occurred. nil if no error occurred.
A boolean value. true, when stopped. Use FileDown:stop() to stop.
A boolean value. true, if finished successfully or stopped or an error occurred.
The number of Bytes already downloaded.
The size in Bytes of the File to download.
The speed in Bytes per second.