123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121typefilename=stringletcompressstr=(* LZ4 forces us to keep the length of the uncompressed string
so that we know it at decompression time *)letn_str=string_of_int(String.lengthstr)inletn=String.lengthn_strinletcompressed=LZ4.Bytes.compress(Bytes.unsafe_of_stringstr)inletm=Bytes.lengthcompressedin(* we write out: <uncompressed_length_str>:<compressed_data> *)letfinal_length=n+1+minletbytes_res=Bytes.createfinal_lengthin(* [0..n-1] *)String.blitn_str0bytes_res0n;(* [n] *)Bytes.setbytes_resn':';(* [n+1..n+m] *)Bytes.blitcompressed0bytes_res(n+1)m;Bytes.unsafe_to_stringbytes_resletuncompressstr=(* first, read the uncompressed length prefix *)leti=String.indexstr':'inletlen=int_of_string(String.substr0i)in(* then, uncompress the rest *)letn=String.lengthstrinletj=i+1inletcompressed=Bytes.create(n-j)inBytes.blit_stringstrjcompressed0(n-j);Bytes.unsafe_to_string(LZ4.Bytes.decompress~length:lencompressed)moduleROZ=structmoduleRO=Dokeysto.Db.ROtypet=RO.tletopen_existingfn=RO.open_existingfnletdummy()=RO.dummy()letclosedb=RO.closedbletmemdbk=RO.memdbkletfinddbk=uncompress(RO.finddbk)letraw_readdbpos=uncompress(RO.raw_readdbpos)letiterfdb=RO.iter(funkz->fk(uncompressz))dbletfoldfdbinit=RO.fold(funkzacc->fk(uncompressz)acc)dbinitendmoduleRWZ=structmoduleRW=Dokeysto.Db.RWtypet=RW.tletcreatefn=RW.createfnletopen_existingfn=RW.open_existingfnletdummy()=RW.dummy()letclosedb=RW.closedbletsyncdb=RW.syncdbletdestroydb=RW.destroydbletmemdbk=RW.memdbkletadddbkstr=RW.adddbk(compressstr)letreplacedbkstr=RW.replacedbk(compressstr)letremovedbk=RW.removedbkletfinddbk=uncompress(RW.finddbk)letraw_readdbpos=uncompress(RW.raw_readdbpos)letiterfdb=RW.iter(funkz->fk(uncompressz))dbletfoldfdbinit=RW.fold(funkzacc->fk(uncompressz)acc)dbinitend