y-crdt / ypy

Python bindings to y-crdt
https://ypy.readthedocs.io/en/latest/
Other
175 stars 21 forks source link

How to read in ydoc binary from file? #155

Open ihasdapie opened 6 months ago

ihasdapie commented 6 months ago

Not sure if this is a trivial question or not, but i've been trying to load in a ydoc binary from a file on disk to no success. So far I've tried:

local_doc = YDoc()

def get_fbytes(fpath):
    with open(fpath, 'rb') as f:
        return f.read()
sv = get_fbytes(FNAME)
apply_update(local_doc, sv)

and then getting elements out of local_doc. However, this is not working.

How can I load in and work with a ydoc from a file? Also, what is the recommended way of going through the elements of a ydoc? I saw another issue that suggests there's no good interface for this via ypy yet. If this is the case, how can we check if a key exists? Since all the get_{text, array, ...} methods will create the element if it doesn't already exist.

If someone can point me in the right direction for where to make these changes to support this in the library, i'd be happy to make a PR.

Thanks!

davidbrochart commented 6 months ago

It's unlikely that you get an answer, since ypy is unmaintained. You might want to look at pycrdt.