Hi all,
I've been implementing a virtual file system in Gambit; the idea is that I can open a file for input and it could be transparently sourced from a .zip file, or the local filesystem, http connection, etc., and a suitable newly-created port would be returned that the caller can do the usual character and byte I/O with.
So for example if a request resolves to a local file, then open-input-port is used, if it's a compressed file, then a different port would be used that handles the decompression.
Two issues:
1) In the case of reading from a .zip, Gambit obviously doesn't have a port for this, so it seemed to me that creating a new custom port type would be ideal. Is there an official / easy way to do this?
(A simplified low-level user port type would be great, in the style used by many C libraries, ie user provides read-bytes, write-bytes, seek and tell functions.)
2) For now I've implemented .zip functionality by extracting the required file to a u8vector, then creating a u8vector-input-port on that, and returning it. Good idea... except that I find out the hard way that input-port-byte-position doesn't work on u8vector ports. This seems to indicate that I can't do random access binary I/O on them using the port functions...? I realise it's not a "device port" but it seems a logical thing to want to do in general.
Btw, reading the list archives from 2006 there was a discussion on the behaviour of input-port-byte-position returning the *buffered* position not the read-u8 cursor position. FWIW, my vote is for the read-u8 position, the current behaviour totally caught me out and isn't particularly usable. :)
Thanks, Darren
Afficher les réponses par date