Further fix npm documentation, minor code review

This commit is contained in:
Raymond Hill 2024-10-06 17:03:18 -04:00
parent 9233e6b7c6
commit 86aeae75df
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 17 additions and 8 deletions

View File

@ -90,10 +90,20 @@ if ( snfe.matchRequest({
}
```
It is possible to pre-parse filter lists and save the intermediate results for
later use -- useful to speed up the loading of filter lists. This will be
documented eventually, but if you feel adventurous, you can look at the code
and use this capability now if you figure out the details.
Once all the filter lists are loaded into the static network filtering engine,
you can serialize the content of the engine into a JS string:
```js
const serializedData = await snfe.serialize();
```
You can save and later use that JS string to fast-load the content of the
static network filtering engine without having to parse and compile the lists:
```js
const snfe = await StaticNetFilteringEngine.create();
await snfe.deserialize(serializedData);
```
---

View File

@ -182,8 +182,7 @@ async function useLists(lists, options = {}) {
// Populate filtering engine with resolved filter lists
const promises = [];
for ( const list of lists ) {
const promise = list instanceof Promise ? list : Promise.resolve(list);
promises.push(promise.then(list => consumeList(list)));
promises.push(Promise.resolve(list).then(list => consumeList(list));
}
useLists.promise = Promise.all(promises);
@ -249,12 +248,12 @@ class StaticNetFilteringEngine {
return compileList(...args);
}
serialize() {
async serialize() {
const data = snfe.serialize();
return s14e.serialize(data, { compress: true });
}
deserialize(serialized) {
async deserialize(serialized) {
const data = s14e.deserialize(serialized);
return snfe.unserialize(data);
}