mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-23 15:39:28 -05:00
b0378dc04e
* renames * Refactor proxy into own package, implement middleware pattern don't need these mocha opts anymore fix test no more zunder READMEs fix test * pass request by reference * fix cors path * Move replace_stream to proxy, concat-stream util in network * Pin dependency versions * Revert addDefaultPort behavior * Add READMEs for proxy, network * Update README.md * eslint --fix * set to null not undefined * use delete and bump node types * import cors from package now * parse-domain@2.3.4 * proxy package needs common-tags * move pumpify dep * load through where it's needed, remove unused passthru_stream * remove unneeded getbuffer call Co-authored-by: Gleb Bahmutov <gleb.bahmutov@gmail.com>
30 lines
701 B
TypeScript
30 lines
701 B
TypeScript
import _ from 'lodash'
|
|
import _concatStream from 'concat-stream'
|
|
|
|
type Callback = (buf: Buffer) => void
|
|
type ConcatOpts = {
|
|
encoding?: string
|
|
}
|
|
|
|
/**
|
|
* Wrapper for `concat-stream` to handle empty streams.
|
|
*/
|
|
export const concatStream: typeof _concatStream = function (opts: Callback | ConcatOpts, cb?: Callback) {
|
|
let _cb: Callback = cb!
|
|
|
|
if (!_cb) {
|
|
_cb = opts as Callback
|
|
opts = {}
|
|
}
|
|
|
|
return _concatStream(opts as ConcatOpts, function (buf: Buffer) {
|
|
if (!_.get(buf, 'length')) {
|
|
// concat-stream can give an empty array if the stream has
|
|
// no data - just call the callback with an empty buffer
|
|
return _cb(Buffer.from(''))
|
|
}
|
|
|
|
return _cb(buf)
|
|
})
|
|
}
|