Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onCompleted: sinon.stub()
}
}
this.mocks.QueryExecutor = sinon.stub().returns(this.mocks.queryExecutor)
this.mocks.Responder = sinon.stub().returns(this.mocks.responder)
this.mocks.SubscribeCallbacks = sinon.stub().returns(this.mocks.subscribeCallbacks)
// proxyquire
this.DataHandler = proxyquire('../src/server/data-handler.js', {
'./active-subscriptions.js': this.mocks.activeSubscriptions,
'./query-executor.js': this.mocks.QueryExecutor,
'./responder.js': this.mocks.Responder,
'./subscribe-callbacks.js': this.mocks.SubscribeCallbacks
})
var toServer = through2.obj()
var toClient = through2.obj()
this.primusClient = duplexify.obj(toServer, toClient)
this.spark = duplexify.obj(toClient, toServer)
this.spark.id = 'sparkId'
})
emitError: true
}, options);
const forkStream = new ForkStream({
classifier: (file, cb) => cb(null, !!condition(file))
});
forkStream.a.pipe(conditionStream);
// merge-stream package cannot be updated because it emits the error
// from conditionStream to mergedStream
const mergedStream = mergeStream(forkStream.b, conditionStream);
const outStream = through2.obj();
mergedStream.pipe(outStream);
const duplexStream = duplexify.obj(forkStream, outStream);
if (options.emitError) {
conditionStream.on('error', err => duplexStream.emit('error', err));
}
return duplexStream;
}
};
GrpcService.prototype.requestWritableStream = function(protoOpts, reqOpts) {
var stream = protoOpts.stream = protoOpts.stream || duplexify.obj();
if (global.GCLOUD_SANDBOX_ENV) {
return stream;
}
var self = this;
if (!this.grpcCredentials) {
// We must establish an authClient to give to grpc.
this.getGrpcCredentials_(function(err, credentials) {
if (err) {
stream.destroy(err);
return;
}
self.grpcCredentials = credentials;
function createStream (script, opts_) {
var opts = opts_ || {}
var duplex = duplexify.obj(null, null)
function errback(err) {
if (err) duplex.destroy(err)
}
// Find the cscript binary. If we're on 64-bit Windows and 32-bit
// Node.js then prefer the native "Sysnative\cscript.exe", because
// otherwise we would be redirected to "SysWow64\cscript.exe" and
// then be unable to access the native registry (without resorting
// to the slower ExecMethod). See also win-detect-browsers#18.
wbin('cscript', { native: opts.native }, function(err, bin) {
if (err) return duplex.destroy(err)
var args = ['//Nologo', '//B', resolve(script)].concat(opts.args || [])
var child = execFile(bin, args, errback)
// special constructor treatment for native websockets in browsers, see
// https://github.com/maxogden/websocket-stream/issues/82
if (isNative && isBrowser) {
socket = new WS(target, protocols)
} else {
socket = new WS(target, protocols, options)
}
socket.binaryType = 'arraybuffer'
}
// was already open when passed in
if (socket.readyState === socket.OPEN) {
stream = proxy
} else {
stream = duplexify.obj()
socket.onopen = onopen
}
stream.socket = socket
socket.onclose = onclose
socket.onerror = onerror
socket.onmessage = onmessage
proxy.on('close', destroy)
var coerceToBuffer = !options.objectMode
function socketWriteNode(chunk, enc, next) {
// avoid errors, this never happens unless
// destroy() is called
Dat.prototype.createMergeStream = function (headA, headB, opts) {
if (!this.opened) return this._createProxyStream(this.createMergeStream, [headA, headB, opts])
if (!opts) opts = {}
if (!headA || !headB) throw new Error('You need to provide two nodes')
debug('createMergeStream', headA, headB, opts)
var valueEncoding = this._getValueEncoding(opts.valueEncoding)
var self = this
var operations = []
var stream = duplexify.obj()
var write = function (data, enc, cb) {
operations.push({
type: data.type === 'del' ? DELETE : PUT,
dataset: data.dataset,
key: data.key,
value: valueEncoding.encode(data.value)
})
cb()
}
stream.on('prefinish', function () {
stream.cork()
self._commit([headA, headB], messages.COMMIT_TYPE.DATA, operations, opts.message, function (err, head) {
if (err) return stream.destroy(err)
.pipe(resolveSymlinks(options))
.pipe(through.obj(createFile));
if (options.since != null) {
outputStream = outputStream
.pipe(filterSince(options.since));
}
if (options.read !== false) {
outputStream = outputStream
.pipe(getContents(options));
}
if (options.passthrough === true) {
inputPass = through.obj();
outputStream = duplexify.obj(inputPass, merge(outputStream, inputPass));
}
if (options.sourcemaps === true) {
outputStream = outputStream
.pipe(sourcemaps.init({loadMaps: true}));
}
globStream.on('error', outputStream.emit.bind(outputStream, 'error'));
return outputStream;
}
if (!opts.objectMode) {
second.push(JSON.stringify(item))
return
}
second.push(item)
})
})
second.end()
})
.catch((err) => {
if (err.message && err.message.indexOf('is this a zip') !== -1) {
err = new Error('Legacy XLS files are not supported, use an XLSX file instead!')
}
second.emit('error', err)
})
return duplex.obj(input, second)
}
var websocketSubProtocol =
(opts.protocolId === 'MQIsdp') && (opts.protocolVersion === 3)
? 'mqttv3.1'
: 'mqtt'
setDefaultOpts(opts)
var url = buildUrl(opts, client)
socketTask = wx.connectSocket({
url: url,
protocols: websocketSubProtocol
})
proxy = buildProxy()
stream = duplexify.obj()
stream._destroy = function (err, cb) {
socketTask.close({
success: function () {
cb && cb(err)
}
})
}
var destroyRef = stream.destroy
stream.destroy = function () {
stream.destroy = destroyRef
var self = this
process.nextTick(function () {
socketTask.close({
fail: function () {
resolveStream (arg, id) {
var { streamType, objectMode } = arg
var ds = objectMode ? duplexify.obj() : duplexify()
if (streamType & READABLE) {
var rs = through({ objectMode })
var rsT = this.getTransportStream(id, READABLE, rs)
pump(rsT, maybeConvert(false, objectMode), rs)
ds.setReadable(rs)
}
if (streamType & WRITABLE) {
var ws = through({ objectMode })
var wsT = this.getTransportStream(id, WRITABLE, ws)
pump(ws, maybeConvert(objectMode, false), wsT)
ds.setWritable(ws)
}
return ds
}