-
Notifications
You must be signed in to change notification settings - Fork 86
Description
I'm trying to find the right APIs to accomplish the following two things.
Do these APIs already exist somewhere that I haven't been able to find?
If not, can I construct them somehow? I particularly would like to keep buffer copying and allocations to a minimum. In both cases, it seems like APIs exist that get me partway there but not all the way.
Synchronous encode/decode
Establish a pipeline that accepts input via an IBufferWriter<byte> that this library implements, and emits output via an IBufferWriter<byte> that I provide. This pipeline should be able to encode or decode.
I'm hoping for something like this:
class LZ4Writer(IBufferWriter<byte> compressedReceiver) : IBufferWriter<byte>
{
public void Complete();
}
class LZ4Reader(IBufferWriter<byte> decompressedReceiver) : IBufferWriter<byte>
{
}I could then pass the LZ4Writer object to anything that writes binary data, and it would automatically compress before being forwarded on to whatever disk, IPC or network needs it.
Similar with LZ4Reader but in reverse.
Async encode/decode
This is pretty much just the first example, but async using PipeReader/PipeWriter. And ideally it would be a trivial hookup:
public static class LZ4Extensions
{
public static PipeReader LZ4Encode(this PipeReader uncompressedData);
public static PipeReader LZ4Decode(this PipeReader compressedData);
}So then I could create a Pipe and chain its reader through LZ4, start writing bunches of bytes to it, and concurrently LZ4 will be compressing or decompressing it on its way somewhere.