diff --git a/dol/__init__.py b/dol/__init__.py index c7afc1e0..277bcfc8 100644 --- a/dol/__init__.py +++ b/dol/__init__.py @@ -113,6 +113,7 @@ def ihead(store, n=1): chain_get, # a function to perform chained get operations (i.e. path keys get) written_bytes, # transform a file-writing function into a bytes-writing function written_key, # writes an object to a key and returns the key. + read_from_bytes, # transform a file-reading function into a bytes-reading function ) from dol.trans import ( diff --git a/dol/filesys.py b/dol/filesys.py index e6b98629..e128d61e 100644 --- a/dol/filesys.py +++ b/dol/filesys.py @@ -567,6 +567,22 @@ class TextFiles(FileStringPersister): json_bytes_wrap = wrap_kvs(obj_of_data=json.loads, data_of_obj=json.dumps) +# And two factories to make the above more configurable: +def mk_pickle_bytes_wrap(*, loads_kwargs: dict, dumps_kwargs: dict) -> Callable: + """""" + return wrap_kvs( + obj_of_data=partial(pickle.loads, **loads_kwargs), + data_of_obj=partial(pickle.dumps, **dumps_kwargs), + ) + + +def mk_json_bytes_wrap(*, loads_kwargs: dict, dumps_kwargs: dict) -> Callable: + return wrap_kvs( + obj_of_data=partial(json.loads, **loads_kwargs), + data_of_obj=partial(json.dumps, **dumps_kwargs), + ) + + @pickle_bytes_wrap class PickleFiles(Files): """A store of pickles"""