Hi Pepijn,

The full comment you refer to says:

// DO NOT CALL THIS except at the top level of your program, e.g. in
main(). Anywhere else, you
// should instead have your caller pass in a Filesystem object, or a
specific Directory object,
// or whatever it is that your code needs. This ensures that your code
supports dependency
// injection, which makes it more reusable and testable.

As the comment says, the idea is that you construct your Filesystem object
at the top level of your program, then you pass it (or specific File or
Directory objects) down to whatever parts of your program need it. That
ensures that those parts of your program can easily be unit-tested against
a fake in-memory filesystem, by swapping out the objects that you pass
down. This is trying to help you make your code more flexible, but you can
ignore it if you want.

You also don't have to use the KJ filesystem API. In fact, nothing else in
KJ or Cap'n Proto cares what you use to open files. KJ is a toolkit,
meaning it provides a bunch of tools, but doesn't force you to use them if
you don't want to.

KJ documentation can be found here:
https://github.com/capnproto/capnproto/tree/master/kjdoc

Please note that Cap'n Proto and KJ are open source software provided for
free. I'd like them to be useful but I don't get any actual benefit from
you using them, and I'm not interested in helping people who are rude. So,
if you have further questions, please try to tone it down a bit. Thanks.

-Kenton

On Wed, Mar 3, 2021 at 5:54 AM [email protected] <[email protected]>
wrote:

> Hey,
>
> I'm just getting started and pretty confused.
> The RPC server is all async and stuff, so no blocking IO in there.
> Then there are some vague mentions that you should use KJ for most things.
> But KJ documentation is nowhere to be found...
>
> All I want to do is just open a file and write to it.
> After resorting to reading the source code, I found
>
> https://github.com/capnproto/capnproto/blob/master/c%2B%2B/src/kj/filesystem.h
> So I managed to create a path so far.
> Then I started to look for how to open a file.
> I found some methods on Directory.
> So then I started to look how to make a directory.
> Then I found a Filesystem, which is abstract.
> Then I found newDiskFilesystem which tells me
> DO NOT CALL THIS except in main()
> Well **** how am I supposed to open a file inside my server handler then??
>
> Pepijn
>
> --
> You received this message because you are subscribed to the Google Groups
> "Cap'n Proto" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/capnproto/cd5ce66c-b12e-4612-b383-32462f047f69n%40googlegroups.com
> <https://groups.google.com/d/msgid/capnproto/cd5ce66c-b12e-4612-b383-32462f047f69n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/capnproto/CAJouXQn_%3Dd05PVOYzWFpAKq_31PKhw%3Dm8mZSJEKriVXAP%3Duffw%40mail.gmail.com.

Reply via email to