[racket] get-pure-port/seekable
Hi, all.
I want to make a custom input port that behaves like one returned from
get-pure-port, but, also handles file-position.
Simple use example:
(let ([in (get-pure-port/seekable uri)])
(display (read-bytes 16 in))
(file-position in 0)
(display (read-bytes 16 in)) ; gets same bytes as above
To handle (file-position N) where N isn't already the current
position, it abandons and reopens the connection using the HTTP header
"Range: bytes=N-" (when servers support it). Subsequent reads from the
port get the entity from N onward.
Simple, and I have some code that works correctly. But using it
requires special open/read/position/close functions. Instead, I want
any code that knows how to use open-input-file ports and
file-position, to be able to use this transparently. So it doesn't
need to know or care if the port is a local file or an HTTP entity.
So I need a custom port, right? But of the various callback functions
I may provide to make-input-port, I don't see the one I need: A way to
set the current position. Gah.
I've been through the docs many times and I'm stumped. Any ideas? Thank you.