Exemple #1
0
    (routes, next) => {
      Insync.each(routes, (route, cb) => {
        if (!route.handler) {
          return cb();
        }

        route.handler.remove({}, cb);
      }, next);
    },
Exemple #2
0
      return Fs.readdir(file, function readdirCb (err, files) {
        if (err) {
          return callback(err);
        }

        zip.addEmptyDirectory(basename, {
          mtime: stats.mtime,
          mode: stats.mode
        });

        Insync.each(files, function dirIterator (dirEntry, cb) {
          addFile(Path.join(file, dirEntry), basename, zip, cb);
        }, callback);
      });
Exemple #3
0
module.exports = function zip (options, callback) {
  const inputs = [].concat(options.input);
  const zip = new Yazl.ZipFile();
  const cwd = options.cwd || process.cwd();

  Insync.each(inputs, function inputIterator (input, next) {
    if (typeof input === 'string') {
      return addFile(Path.resolve(cwd, input), '', zip, next);
    }

    if (input !== null && typeof input === 'object') {
      const data = typeof input.data === 'string' ? Buffer.from(input.data) :
                                                    input.data;

      zip.addBuffer(data, input.name, {
        mtime: new Date(),
        mode: 0o100755
      });

      return next();
    }

    next(new TypeError(`input must be a string or object, but got ${input}`));
  }, function inputCb (err) {
    if (err) {
      return callback(err);
    }

    const chunks = [];
    let outputSize = 0;

    zip.outputStream.on('error', function onError (err) {
      callback(err);
    });

    zip.outputStream.on('data', function onData (chunk) {
      outputSize += chunk.length;
      chunks.push(chunk);
    });

    zip.outputStream.on('finish', function onFinish () {
      const output = Buffer.concat(chunks, outputSize);

      callback(null, output);
    });

    zip.end();
  });
};
Exemple #4
0
Client.prototype.report = function report (message, callback) {
  if (typeof callback !== 'function') {
    callback = noop;
  }

  if (typeof message !== 'string') {
    message = tryStringify(message);

    if (message instanceof Error) {
      return callback(message);
    }
  }

  Insync.each(this._reporters, function eachIterator (reporter, next) {
    reporter.report(message, next);
  }, callback);
};
Exemple #5
0
    it('errors on schema violations', (done) => {
      const m = new Manager({ errors: { policy: 'throw' }});
      const plugins = [
        undefined,
        null,
        '',
        1,
        false,
        {},
        { plugin: null },
        { plugin: 'foo' },
        { plugin: {} },
        { plugin: { register: 1 } }
      ];

      Insync.each(plugins, (plugin, cb) => {
        m.register(plugin, (err) => {
          expect(err).to.be.an.instanceof(TypeError);
          cb();
        });
      }, done);
    });
Exemple #6
0
  server.auth.scheme('nuisance', function nuisanceScheme (server, options) {
    Assert.strictEqual(Array.isArray(options.strategies), true);

    return {
      authenticate (request, reply) {
        const credentials = {};
        let scope = [];

        Insync.each(options.strategies, function eachIterator (strategy, next) {
          server.auth.test(strategy, request, function testCb (err, creds) {
            if (err) {
              return next(err);
            }

            credentials[strategy] = creds;

            if (creds !== null && typeof creds === 'object' && creds.scope) {
              scope = scope.concat(creds.scope);
            }

            next();
          });
        }, function eachCb (err) {
          if (err) {
            return reply(Boom.unauthorized());
          }

          if (scope.length !== 0) {
            credentials.scope = scope;
          }

          reply.continue({ credentials });
        });
      }
    };
  });
Exemple #7
0
function benchInsyncEach (done) {
  insync.each([1, 2, 3], somethingP, done)
}