-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* cache integrity and size events so late listeners still get them * pass expected integrity to cacache * pass integrityEmitter to cacache to avoid a redundant integrity stream * remove in-memory buffering in favor of full time streaming
- Loading branch information
1 parent
632ce87
commit 7b2b77a
Showing
6 changed files
with
109 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict' | ||
|
||
const MinipassPipeline = require('minipass-pipeline') | ||
|
||
class CachingMinipassPipeline extends MinipassPipeline { | ||
#events = [] | ||
#data = new Map() | ||
|
||
constructor (opts, ...streams) { | ||
// CRITICAL: do NOT pass the streams to the call to super(), this will start | ||
// the flow of data and potentially cause the events we need to catch to emit | ||
// before we've finished our own setup. instead we call super() with no args, | ||
// finish our setup, and then push the streams into ourselves to start the | ||
// data flow | ||
super() | ||
this.#events = opts.events | ||
|
||
/* istanbul ignore next - coverage disabled because this is pointless to test here */ | ||
if (streams.length) { | ||
this.push(...streams) | ||
} | ||
} | ||
|
||
on (event, handler) { | ||
if (this.#events.includes(event) && this.#data.has(event)) { | ||
return handler(...this.#data.get(event)) | ||
} | ||
|
||
return super.on(event, handler) | ||
} | ||
|
||
emit (event, ...data) { | ||
if (this.#events.includes(event)) { | ||
this.#data.set(event, data) | ||
} | ||
|
||
return super.emit(event, ...data) | ||
} | ||
} | ||
|
||
module.exports = CachingMinipassPipeline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters