# TCastleZip and virtual file systems

**URL:** https://forum.castle-engine.io/t/tcastlezip-and-virtual-file-systems/1830
**Category:** Uncategorized
**Created:** [March 19, 2025, 5:38am UTC](https://forum.castle-engine.io/t/tcastlezip-and-virtual-file-systems/1830 "2025-03-19T05:38:33Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [March 19, 2025, 12:18pm UTC](https://forum.castle-engine.io/t/tcastlezip-and-virtual-file-systems/1830/2 "2025-03-19T12:18:38Z")

</div>

Oh, I think we already have something you ask for, though it’s not a class 🙂

Namely, you can use global routine [RegisterUrlProtocol](https://castle-engine.io/apidoc/html/CastleDownload.html#RegisterUrlProtocol-String-TUrlReadEvent-TUrlWriteEvent-TUrlAsynchronousReaderClass-Boolean-) to register your own URL protocol, with custom callbacks for reading and writing. This way all the engine reading/writing routines will recognize the new URL protocol.

In effect, a virtual filesystem is defined by the callbacks (and you can naturally implement them all by a single class, which is what `TCastleZip` does). There are 3 callbacks provided to `RegisterUrlProtocol` now, all optional:

- asynchronous reader
- synchronous reader (just return readable TStream for the resource)
- writer (just return writeable TStream for the resource)

I want to keep extending this API, add additional callbacks to

- check file/directory existence (so that [UriExists](https://castle-engine.io/apidoc/html/CastleUriUtils.html#UriExists-String-) can handle the custom protocol). This should happen soon, it’s necessary for one [top-secret project I do to showcase our web support](https://forum.castle-engine.io/t/video-overview-of-the-new-features-web-ifc-zip/1826/4) 🙂
- enumerate directory contents (so that you can search arbitrary filesystems with [FindFiles](https://castle-engine.io/apidoc/html/CastleFindFiles.html#FindFiles-string-string-boolean-TFoundFileMethod-TFindFilesOptions-) ). This is also on TODO, though not immediate.

Possibly, at some point [RegisterUrlProtocol](https://castle-engine.io/apidoc/html/CastleDownload.html#RegisterUrlProtocol-String-TUrlReadEvent-TUrlWriteEvent-TUrlAsynchronousReaderClass-Boolean-) will take a record/class with these callbacks, to avoid having a procedure with zillion optional parameters 🙂

I have just reworked our [documentation about URLs, loading (downloading) and saving resources](https://castle-engine.io/url) so hopefully it nicely documents / links to our capabilities in this regard.

See and run [castle-engine/examples/network/custom\_url\_handler at master · castle-engine/castle-engine · GitHub](https://github.com/castle-engine/castle-engine/tree/master/examples/network/custom_url_handler) (without the `USE_ZIP_URL_HANDLER` symbol defined) for a demo how `RegisterUrlProtocol` can be used.

---

_[View the full topic](https://forum.castle-engine.io/t/tcastlezip-and-virtual-file-systems/1830)._
