HTTP allows you to specify byte ranges for requests. This allows the implementation of resumable downloads and skippable audio and video streams alike. The following example uses a text file to make the range request process easier.
shell> cat file.txt
My hovercraft is full of eels!
Uploading this as an attachment to a text
database using curl:
shell> curl -X PUT http://127.0.0.1:5984/test/doc/file.txt \
-H "Content-Type: application/octet-stream" -d@file.txt
{"ok":true,"id":"doc","rev":"1-287a28fa680ae0c7fb4729bf0c6e0cf2"}
Requesting the whole file works as normal:
shell> curl -X GET http://127.0.0.1:5984/test/doc/file.txt
My hovercraft is full of eels!
But to retrieve only the first 13 bytes using curl:
shell> curl -X GET http://127.0.0.1:5984/test/doc/file.txt -H "Range: bytes=0-12"
My hovercraft
HTTP supports many ways to specify single and even multiple byte rangers. See RFC 2616.
Databases that have been created with CouchDB 1.0.2 or earlier will support range requests in 1.1.0, but they are using a less-optimal algorithm. If you plan to make heavy use of this feature, make sure to compact your database with CouchDB 1.1.0 to take advantage of a better algorithm to find byte ranges.