问题
When accepting an input buffer, and knowing compression is a CPU bound task, does it needs to offer a callback? Is it just there to follow common practice like callback(err, result)
?
Doc: http://nodejs.org/api/zlib.html#zlib_zlib_deflate_buf_callback
回答1:
The compression/decompression is executed in a separate thread and not in the main thread. That is why a callback is needed for when the thread completes its work.
The callback style is the same common signature used throughout node and most third-party modules (error first).
来源:https://stackoverflow.com/questions/25220266/why-zlib-deflatebuf-callback-is-async