This is the compression class. It'll help you with compressing data sync or async. More information about this compression can be found in the tutorials.
With this function you can asynchronously compress data. This means this function will immediately compress the data instead of having to use a stream. The data you want to compress is specified with the data parameter. You can also override the settings using the opts parameter. This function will return a promise that calls the "data" event when the data has been compressed, with the data as first argument, and the "error" event when there was an error while compressing the data.
var compression = cerus.compression();
compression.compress("example string");
// -> this function will compress the string "example string"
This function returns the compression.constants class. If the class hasn't been created yet, it will create it.
With this function you can force the compression stream to buffer all the data to the memory. By doing this a situation can be avoided where a backup would be created when a lot of small chunks of data are added to the internal buffer. When this happens performance will be heavily impacted. This behaviour is stopped using the .uncork() function or when the stream is ended. This function will throw an error when the stream hasn't been started yet.
With this function you can destroy the compression stream. Destroying it is basically ending it with a possible error. This error can be inserted using the error parameter. You can get this error from the "error" event. This function will throw an error when the stream hasn't started yet.
var compression = cerus.compression();
compression.open();
compression.destroy(new Error("destroyed"));
// -> this function will destroy the compression stream and throw the error "destroyed"
This function will end the compression stream. While ending the stream you can also supply the last data that will be written to the stream. The data you want to write to the stream is specified with the chunk parameter. You can also set the encoding it will be written in using the encoding parameter. This function will throw an error when the stream hasn't been opened yet when this function is called. This function will also return a promise that calls the "ended" event when the stream has succesfully ended and all the data has been flushed.
var compression = cerus.compression();
compression.open();
compression.end("data");
// -> this function will write the string "data" to the compression stream end then end the stream
This function returns a promise that will call a number of events. The "drain" event is called when something has been written to the stream and the stream is ready to be written to again. The "error" event is called when there was an error somewhere in the stream. The "finish" event is called when the compression.end() function has been called. The "pipe" event is called when the .pipe() function is used on a readable stream and the "unpipe" event when the .unpipe() function is used. This function will throw an error when when the stream has not been opened yet.
With this function you can open the compression stream. Opening it means you can start writing data, which will be compressed. You can also add the options you want. They will be overwritten by the settings if you don't add them.
This function returns the settings class. With this class you can change the settings for how the data will be compressed. You can also change the compression type with this class.
This function will return the compression stream. It will be undefined until you've opened it. This stream is used for async compression. Use .compress() when you want to compress it synchronously.
Using this function you can stop the behaviour that was started using the .cork() method. This can also be done by ending the compression stream. This function will throw an error when the stream hasn't been started yet.
With this function you can write to the compression stream. What you write to the compression stream is defined with the chunk parameter. You can also change the encoding with the encoding parameter. There will be an error of the stream has not been opened yet. This function will return a promise that calls the "written" event when the data has been written to the compression stream.
var compression = cerus.compression();
compression.open();
compression.write("data");
// -> this function will write the string "data" to the compression stream