Writing a package downloader
Overview
Packages need to be downloaded from REBOL.org to the local machine before they can be used.
A standard downloader is provided to do this. All your script needs to run that is a single line of executable code, eg:
do http://www.rebol.org/library/public/repack.r
But there may be times when that standard downloader does not fit your needs:
- You have a complex download / configure / install process. Various files may be selected or not according to the configuration stage. And you don't want to break it into separate parts -- so you don't want to run the standard downloader
- You want to use REBOL features in downloading that are not available in the standard downloader. (The standard downloader is written to be generic, so it does not use many of the more recent REBOL embellishments)
- You want to download files from places other than the package
- Your package files are encrypted
- You just want to write a better downloader
- You just feel like it
Whatever your reasons, if you want to do it, you can. And the rest of this page explains how.
Where to put your downloader/installer
There are four obvious places:
[1/4] In REBOL.org/library/public
i.e. it lives along with the standard downloader. You'd need to negotiate with the Librarians about this. If your downloader is sufficiently generic (it could be used with other packages), we might say yes.
[2/4] As a contributed script in REBOL.org
That would make some sense if the downloader had some wider use -- perhaps all your packages need it. But it wouldn't be a script that anyone would need to know about unless they wanted to install your package. As such, this option may make it just a little too visible
[3/4] On your website
You could put it on your website. The line of code to invoke it would then be something like:
do http://www.your-site.com/your-package-downloader.r
The problem there is that a download of your package is dependent on both REBOL.org and your website being available. The Internet being what it is, that doubles the chance of unavailability.
[4/4] In the package itself
This is the most obvious place for a package-specific downloader. It lives with the package itself, so all the files needed are in one place
This fourth choice is the recommended option
But it leads to the question: "How do I run my downloader to extract files from the package if my downloader is in the package?"
Luckily, there is a very simple answer. Your script just needs three lines of code:
do http://www.rebol.org/library/public/lds-local.r
downloader: lds/send-server 'get-package-file ["your-package-name/your-downloader-file-name"]
do load decompress downloader/data/file
Your choice
Whichever of the four methods you use, your downloader will be written in much the same way as described below
Writing the downloader
To get at the files in your package, you must use the Library Data Services interface. (There is no other way: the files in your package are not held as separate files, so there is no secret URL you can discover to bypass using LDS).
Starting LDS
It is possible that the user already has a copy on their local machine. If so, don't trust it! It may be out of date. Always use the version on REBOL.org:
do http://www.rebol.org/library/public/lds-local.r
You don't need to download it, running direct from REBOL.org will work fine
Using LDS
There are two LDS requests that matter for downloading a package:
- get-package-header -- retrieves the list of files in the package
- get-package-file -- retrieves a specific file from the package
These are described in more detail in the Library Data Services documentation.
If you do write your own downloader, good luck with it!
Sample downloaders
Use these for inspiration or guidance:
repack.r-- the Library's standard downloader. Note that this loads one of three code bases, depending on whether the version of REBOL you are running is CORE or VIEW.
lds-package-downloader.r-- the orginal downloader, now superseded by repack.r and repack-core.r