CoolFace
Apppublic

opusdev/vector-similarity-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
index.js70 linesDownload Raw Back to unpipe
1/*!2 * unpipe3 * Copyright(c) 2015 Douglas Christopher Wilson4 * MIT Licensed5 */6 7'use strict'8 9/**10 * Module exports.11 * @public12 */13 14module.exports = unpipe15 16/**17 * Determine if there are Node.js pipe-like data listeners.18 * @private19 */20 21function hasPipeDataListeners(stream) {22  var listeners = stream.listeners('data')23 24  for (var i = 0; i < listeners.length; i++) {25    if (listeners[i].name === 'ondata') {26      return true27    }28  }29 30  return false31}32 33/**34 * Unpipe a stream from all destinations.35 *36 * @param {object} stream37 * @public38 */39 40function unpipe(stream) {41  if (!stream) {42    throw new TypeError('argument stream is required')43  }44 45  if (typeof stream.unpipe === 'function') {46    // new-style47    stream.unpipe()48    return49  }50 51  // Node.js 0.8 hack52  if (!hasPipeDataListeners(stream)) {53    return54  }55 56  var listener57  var listeners = stream.listeners('close')58 59  for (var i = 0; i < listeners.length; i++) {60    listener = listeners[i]61 62    if (listener.name !== 'cleanup' && listener.name !== 'onclose') {63      continue64    }65 66    // invoke the listener67    listener.call(stream)68  }69}70