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

To help you get started, we’ve selected a few is-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 stolksdorf / vitreum / node_modules / gulp-nodemon / node_modules / nodemon / node_modules / update-notifier / node_modules / latest-version / node_modules / package-json / node_modules / got / index.js View on Github external
delete opts.body;
	delete opts.json;
	delete opts.timeout;

	if (json) {
		opts.headers.accept = opts.headers.accept || 'application/json';
	}

	if (body) {
		if (typeof body !== 'string' && !Buffer.isBuffer(body) && !isStream.readable(body)) {
			throw new GotError('options.body must be a ReadableStream, string or Buffer');
		}

		opts.method = opts.method || 'POST';

		if (!opts.headers['content-length'] && !opts.headers['transfer-encoding'] && !isStream.readable(body)) {
			var length = typeof body === 'string' ? Buffer.byteLength(body) : body.length;
			opts.headers['content-length'] = length;
		}
	}

	opts.method = opts.method || 'GET';

	// returns a proxy stream to the response
	// if no callback has been provided
	if (!cb) {
		proxy = duplexify();

		// forward errors on the stream
		cb = function (err, data, response) {
			proxy.emit('error', err, data, response);
		};
github ipfs / js-ipfs / src / core / components / files-regular.js View on Github external
        const isBufferOrStream = obj => Buffer.isBuffer(obj) || isStream.readable(obj) || isSource(obj)
        // An object like { content?, path? }, where content isBufferOrStream and path isString
github ipfs / js-ipfs / src / core / components / files-regular.js View on Github external
return content.map((data) => {
    // Buffer input
    if (Buffer.isBuffer(data)) {
      data = { path: '', content: pull.values([data]) }
    }

    // Readable stream input
    if (isStream.readable(data)) {
      data = { path: '', content: toPull.source(data) }
    }

    if (isSource(data)) {
      data = { path: '', content: data }
    }

    if (data && data.content && typeof data.content !== 'function') {
      if (Buffer.isBuffer(data.content)) {
        data.content = pull.values([data.content])
      }

      if (isStream.readable(data.content)) {
        data.content = toPull.source(data.content)
      }
    }
github ipfs-shipyard / ipfs-postmsg-proxy / src / client / files / add.js View on Github external
function fileToJson (file, opts) {
  opts = opts || {}

  if (isBuffer(file)) { // Buffer
    if (opts.onProgressIncrement) opts.onProgressIncrement(file.length)
    return bufferToJson(file)
  } else if (isStream.readable(file)) { // Node stream
    return pullStreamToJson(toPull.source(file), opts)
  } else if (isSource(file)) { // Pull stream
    return pullStreamToJson(file, opts)
  } else if (file && file.content) { // Object { path?, content }
    return Object.assign({}, file, { content: fileToJson(file.content, opts) })
  }

  return file // Object { path } maybe, but could be anything
}
github rhinoman / wikifeat / frontend / web_app / node_modules / grunt-bower-requirejs / node_modules / bower-requirejs / node_modules / update-notifier / node_modules / latest-version / node_modules / package-json / node_modules / got / index.js View on Github external
err = new GotError('Parsing ' + url + ' response failed', e);
					}
				}

				cb(err, data, response);
			});
		}).once('error', function (err) {
			cb(new GotError('Request to ' + url + ' failed', err));
		});

		if (timeout) {
			timedOut(req, timeout);
		}

		if (!proxy) {
			if (isStream.readable(body)) {
				body.pipe(req);
			} else {
				req.end(body);
			}

			return;
		}

		if (body) {
			proxy.write = function () {
				throw new Error('got\'s stream is not writable when options.body is used');
			};

			if (isStream.readable(body)) {
				body.pipe(req);
			} else {
github stolksdorf / vitreum / node_modules / gulp-nodemon / node_modules / nodemon / node_modules / update-notifier / node_modules / latest-version / node_modules / package-json / node_modules / got / index.js View on Github external
err = new GotError('Parsing ' + url + ' response failed', e);
					}
				}

				cb(err, data, response);
			});
		}).once('error', function (err) {
			cb(new GotError('Request to ' + url + ' failed', err));
		});

		if (timeout) {
			timedOut(req, timeout);
		}

		if (!proxy) {
			if (isStream.readable(body)) {
				body.pipe(req);
			} else {
				req.end(body);
			}

			return;
		}

		if (body) {
			proxy.write = function () {
				throw new Error('got\'s stream is not writable when options.body is used');
			};

			if (isStream.readable(body)) {
				body.pipe(req);
			} else {
github transitive-bullshit / functional-typescript / packages / fts-http / src / handler.ts View on Github external
if (obj === null || obj === undefined) {
    res.end()
    return
  }

  if (Buffer.isBuffer(obj)) {
    if (!res.getHeader('Content-Type')) {
      res.setHeader('Content-Type', 'application/octet-stream')
    }

    res.setHeader('Content-Length', obj.length)
    res.end(obj)
    return
  }

  if (obj instanceof Stream || readable(obj)) {
    if (!res.getHeader('Content-Type')) {
      res.setHeader('Content-Type', 'application/octet-stream')
    }

    obj.pipe(res)
    return
  }

  let jsonify = false
  let str = obj

  switch (typeof str) {
    case 'object':
      jsonify = true
      break
    case 'number':
github Sobesednik / node-exiftool / src / lib.js View on Github external
function isReadable(stream) {
    return isStream.readable(stream)
}
function isWritable(stream) {
github ipfs / js-ipfs-http-client / src / files-regular / add.js View on Github external
const add = promisify((_files, options, _callback) => {
    if (typeof options === 'function') {
      _callback = options
      options = null
    }

    const callback = once(_callback)

    if (!options) {
      options = {}
    }
    options.converter = FileResultStreamConverter

    const ok = Buffer.isBuffer(_files) ||
               isStream.readable(_files) ||
               Array.isArray(_files) ||
               OtherBuffer.isBuffer(_files) ||
               typeof _files === 'object' ||
               isSource(_files)

    if (!ok) {
      return callback(new Error('first arg must be a buffer, readable stream, pull stream, an object or array of objects'))
    }

    const files = [].concat(_files)

    const stream = createAddStream({ qs: options })
    const concat = ConcatStream((result) => callback(null, result))
    stream.once('error', callback)
    stream.pipe(concat)

is-stream

Check if something is a Node.js stream

MIT
Latest version published 10 months ago

Package Health Score

79 / 100
Full package analysis