Persistence
cliftonc opened this issue · 4 comments
Thanks for making this library.
Is there any way to serialise the structures into something (e.g. json or a base64 encoded string) so that it can be persisted somewhere and re-instantiated?
Thanks to you for using it ;)
Serialise structures can be handy. I see how it can be done easily, so I will be working on it when I have a little spare time.
I think that a support for serialisation into/from JSON should be enough, as if you have a JSON string, you can generate yourself the associated base64 encoded string.
Added functionality for import/export from/to JSON with 9ee6c9c
Usage:
const BloomFilter = require('bloom-filters').BloomFilter;
const filter = new BloomFilter(15, 0.01);
filter.add('alice');
// export a bloom filter to JSON
const exported = filter.saveAsJSON();
// do something with the JSON object (save it as file, send it to a server, etc)
// ...
// import the same filter from its JSON export
const importedFilter = BloomFilter.fromJSON(exported);
console.log(filter.has('alice')); // output: true
console.log(filter.has('bob')); // output: false
This example has been added to the README
Perfect - thanks for the fast response!
I've also updated the npm release from 0.4.1 to 0.5.0, don't forget to upgrade your dependencies!