Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replace all streams with Minipass streams
BREAKING CHANGE: This subtly changes the streaming interface of everything in cacache that streams, which is, well, everything in cacache. Most users will probably not notice, but any code that depended on stream behavior always being deferred until next tick will need to adjust. The mississippi methods 'to', 'from', 'through', and so on, have been replaced with their Minipass counterparts, and streaming interaction with the file system is done via fs-minipass. The following modules are of interest here: - [minipass](http://npm.im/minipass) The core stream library. - [fs-minipass](http://npm.im/fs-minipass) Note that the 'WriteStream' class from fs-minipass is _not_ a Minipass stream, but rather a plain old EventEmitter that duck types as a Writable. - [minipass-collect](http://npm.im/minipass-collect) Gather up all the data from a stream. Cacache only uses Collect.PassThrough, which is a basic Minipass passthrough stream which emits a 'collect' event with the completed data just before the 'end' event. - [minipass-pipeline](http://npm.im/minipass-pipeline) Connect one or more streams into a pipe chain. Errors anywhere in the pipeline are proxied down the chain and then up to the Pipeline object itself. Writes go into the head, reads go to the tail. Used in place of pump() and pumpify(). - [minipass-flush](http://npm.im/minipass-flush) A Minipass passthrough stream that defers its 'end' event until after a flush() method has completed (either calling the supplied callback, or returning a promise.) Use in place of flush-write-stream (aka mississippi.to). Streams from through2, concat-stream, and the behavior provided by end-of-stream are all implemented in Minipass itself. Features of interest to cacache, which make Minipass a particularly good fit: - All of the 'endish' events are normalized, so we can just listen on 'end' and know that finish, prefinish, and close will be handled as well. - Minipass doesn't waste time [containing zalgo](https://blog.izs.me/2013/08/designing-apis-for-asynchrony). - Minipass has built-in support for promises that indicate the end or error: stream.promise(), stream.collect(), and stream.concat(). - With reliable and consistent timing guarantees, much less error-checking logic is required. We can be more confident that an error is being thrown or emitted in the correct place, rather than in a callback which is deferred, resulting in a hung promise or uncaughtException. The biggest downside of Minipass is that it lacks some of the internal characteristics of node-core streams, which many community modules use to identify streams. They have no _writableState or _readableState objects, or _read or _write methods. As a result, the is-stream module (at least, at the time of this commit) doesn't recognize Minipass streams as readable or writable streams. All in all, the changes required of downstream users should be minimal, but are unlikely to be zero. Hence the semver major change.
- Loading branch information