How to use streamsearch - 2 common examples

To help you get started, we’ve selected a few streamsearch 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 shoutem / cli / src / services / stream-matcher.js View on Github external
export default (stream, pattern) => new Promise((resolve, reject) => {
  const search = new StreamSearch(pattern);
  let matched = false;

  search.on('info', isMatch => {
    if (isMatch) {
      resolve();
      matched = true;
    }
  });
  search.on('error', err => reject(err));
  search.on('finish', () => matched ? null : reject(new Error(`Match ${pattern} not found`)));
  stream.on('data', data => search.push(data));
});
github itchio / itch / appsrc / tasks / install / exe.js View on Github external
builtinSniff: async function (opts, needles) {
    const {archivePath} = opts
    let result = null
    let searches = []

    let onInfo = (needle, format, isMatch, data, start, end) => {
      if (!isMatch) return
      log(opts, `builtinSniff: found needle ${needle}`)
      result = format
    }

    for (const needle of Object.keys(needles)) {
      const format = needles[needle]
      const search = new StreamSearch(needle)
      search.on('info', onInfo::partial(needle, format))
      searches.push(search)
    }

    const reader = sf.createReadStream(archivePath, {encoding: 'binary'})
    reader.on('data', (buf) => {
      for (let search of searches) {
        search.push(buf)
      }
    })

    await sf.promised(reader)
    return result
  },

streamsearch

Streaming Boyer-Moore-Horspool searching for node.js

MIT
Latest version published 2 years ago

Package Health Score

67 / 100
Full package analysis

Popular streamsearch functions