How to use the readable-stream.Duplex function in readable-stream

To help you get started, we’ve selected a few readable-stream examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SyncOT / SyncOT / packages / connection / src / connection.ts View on Github external
if (proxyRequest) {
                    proxyRequests.delete(id)
                    proxyRequest.reject(message.data)
                }
                break
            }

            case MessageType.REPLY_STREAM: {
                const stream = this.stream
                const { id, service } = message
                const proxyRequest = proxyRequests.get(id)

                if (proxyRequest) {
                    proxyRequests.delete(id)

                    const proxyStream = new Duplex({
                        final: (callback: Callback) => {
                            /* istanbul ignore else */
                            if (this.stream === stream) {
                                this.send({
                                    data: null,
                                    id,
                                    name: null,
                                    service,
                                    type: MessageType.STREAM_INPUT_END,
                                })
                            }
                            callback(null)
                        },
                        objectMode: true,
                        read: () => undefined,
                        write: (
github gulpjs / vinyl / test / inspectStream.js View on Github external
it('should work on a core Duplex Stream', function(done) {
    var testStream = new Stream.Duplex();
    inspectStream(testStream).should.equal('');
    done();
  });
github splunk / splunk-sdk-javascript / tests / modularinputs / utils.js View on Github external
root.getDuplexStream = function() {
        var duplex = new Stream.Duplex();
        duplex.data = "";
        duplex._write = function(chunk, enc, next) {
            this.data += chunk.toString();
            next();
        };
        duplex._read = function() {
            return this.data;
        };
        return duplex;
    };
github jsforce / jsforce / lib / browser / canvas.js View on Github external
return function(params, callback) {
      var response;
      var str = new Duplex();
      str._read = function(size) {
        if (response) {
          str.push(response.body);
        }
      };
      var bufs = [];
      var sent = false;
      str._write = function(chunk, encoding, callback) {
        bufs.push(chunk.toString(encoding));
        callback();
      };
      str.on('finish', function() {
        if (!sent) {
          send(bufs.join(''));
          sent = true;
        }
github SyncOT / SyncOT / packages / util / src / stream.ts View on Github external
_encoding: string,
            callback: (error: Error | null) => void,
        ) {
            b.push(data)
            callback(null)
        },
        final(callback: (error: Error | null) => void) {
            b.push(null)
            callback(null)
        },
        destroy(error: Error | null, callback: (error: Error | null) => void) {
            b.destroy()
            callback(error)
        },
    })
    const b = new Duplex({
        allowHalfOpen,
        objectMode,
        read() {
            return
        },
        write(
            data: any,
            _encoding: string,
            callback: (error: Error | null) => void,
        ) {
            a.push(data)
            callback(null)
        },
        final(callback: (error: Error | null) => void) {
            a.push(null)
            callback(null)
github floatdrop / gulp-watch / index.js View on Github external
}

	function resolveGlob(glob) {
		var mod = '';

		if (glob[0] === '!') {
			mod = glob[0];
			glob = glob.slice(1);
		}

		return mod + normalize(resolveFilepath(glob));
	}
	globs = globs.map(resolveGlob);

	var baseForced = Boolean(opts.base);
	var outputStream = new Duplex({objectMode: true, allowHalfOpen: true});

	outputStream._write = function _write(file, enc, done) {
		cb(file);
		this.push(file);
		done();
	};

	outputStream._read = function _read() { };

	var watcher = chokidar.watch(globs, opts);

	opts.events.forEach(function (ev) {
		watcher.on(ev, processEvent.bind(undefined, ev));
	});

	['add', 'change', 'unlink', 'addDir', 'unlinkDir', 'error', 'ready', 'raw']
github jsforce / jsforce / lib / browser / request.js View on Github external
module.exports = function(params, callback) {
  var xhr = new XMLHttpRequest();
  xhr.open(params.method, params.url);
  if (params.headers) {
    for (var header in params.headers) {
      xhr.setRequestHeader(header, params.headers[header]);
    }
  }
  xhr.setRequestHeader("Accept", "*/*");
  var response;
  var str = new Duplex();
  str._read = function(size) {
    if (response) {
      str.push(response.body);
    }
  };
  var bufs = [];
  var sent = false;
  str._write = function(chunk, encoding, callback) {
    bufs.push(chunk.toString(encoding === "buffer" ? "binary" : encoding));
    callback();
  };
  str.on('finish', function() {
    if (!sent) {
      xhr.send(bufs.join(''));
      sent = true;
    }
github SyncOT / SyncOT / packages / util / src / invertedStreams.ts View on Github external
export function invertedStreams({
    allowHalfOpen = true,
    objectMode = false,
} = {}): [Duplex, Duplex] {
    const a = new Duplex({
        allowHalfOpen,
        objectMode,
        read() {
            return
        },
        write(
            data: any,
            _encoding: string,
            callback: (error: Error | null) => void,
        ) {
            b.push(data)
            callback(null)
        },
        final(callback: (error: Error | null) => void) {
            b.push(null)
            callback(null)