The Dat command line comes with a built in HTTP server.
This is a cool demo because we can also see how version history works!
--http option works for files you are sharing or downloading.
(If you don't have dat command line installed, run
npm install -g dat, or see more info.)
Serve over HTTP
Serve dat files on http by adding the
--http option. For example, you can sync an existing dat:
❯ dat sync --http dat://778f8d955175c92e4ced5e4f5563f69bfec0c86cc6f670352c457943666fe639 Sharing dat: 2 files (1.4 MB) Serving files over http at http://localhost:8080 2 connections | Download 0 B/s Upload 0 B/s
http://localhost:8080 to see the files in your browser!
The default http port is 8080. You should see a directory listing:
If your dat has an
index.html page, that will be shown instead.
You can combine Dat's http support with our server tools to create a live updating website or place to share files publicly.
As you may know, Dat automatically versions all files. The HTTP display is an easy way to view version history:
localhost:8080/?version=2 to view a specific version.
The Dat http viewer also comes with live reloading. If it detects a new version it will automatically reload with the new directory listing or page (as long as you aren't viewing a specific version in the url).
Dat supports sparse, or partial downloads, of datasets. This is really useful if you only want a single file from a large dat. Unfortunately, we haven't quite built a user interface for this into our applications. So you can hack around it!
This will allow you to download a single file from a larger dat, without downloading metadata or any other files.
First, start downloading our demo dat, make sure you include both the flags (
❯ dat dat://778f8d955175c92e4ced5e4f5563f69bfec0c86cc6f670352c457943666fe639 ./demo --http --sparse Cloning: 2 files (1.4 MB) Serving files over http at http://localhost:8080 3 connections | Download 0 B/s Upload 0 B/s
--sparse option tells Dat to only download files you specifically request.
See how it works:
- Check out your
./demofolder, it should be empty.
- Open the Dat in your browser.
- Click on a file to download.
- It should be in your folder now!
Pretty cool! You can use this hack to download only specific files or even older versions of files (if they've been saved somewhere).