Add denylist writing functionality
As it stands, the NoPFS library only supports reading the denylist format, but doesn't have any support for writing the denylist to a file. While most applications will only be reading the denylist, there are some that will need to write. It would be best to have both functionalities in the same library, to ensure correct round-tripping.
Given the denylist is plaintext and writing is mostly appending lines to a file, is there anything special that you would expect from this functionality?
I'm thinking:
- Given a CID, generate a multhash rule
- Given a CID or domain, + path, generate a multihash-double-hash rule
- ...
For my current purposes, I'd just like to have a denylist.Write(filename string) function which would overwrite the given file with the current denylist. ATM it's just writing the appropriate header and then looping through the Entries slice and writing RawValue, but it would make it simpler and would also help if we later e.g. add other header fields.
Although the conversions that you mention were not what I was originally thinking of, they would also be REALLY nice, generating different types of rules given CIDs, domains, etc. I had to do a bit of reverse-engineering and I'm still not 100% sure that what I did is correct (currently testing).
If we agree that this belongs here I could make a couple of PRs to add both the write functionality and one or two of the functions, and take it from there.
I'd just like to have a
denylist.Write(filename string)
How is this different from f := os.Open("path", APPEND); f.Write("/ipfs/cid\n") ?
(or just copying the original file).