How to use the is2.buffer function in is2

To help you get started, we’ve selected a few is2 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 strongloop / supercluster / lib / Worker.js View on Github external
if (!is.nonEmptyObj(task))
    return asyncerr(new Error('No task received.'), cb);
  // ensure the task has a filename
  if (!is.str(task.fileName))
    return asyncerr(new Error('Task has no fileName: '+inspect(task)), cb);

  try {
    // convert array representing a buffer into a string
    if (is.array(task.file))
      task.file = new Buffer(task.file);
  } catch(err) {
    return asyncerr(err, cb);
  }

  // ensure we have a string representing the file
  if (!is.buffer(task.file))
    return asyncerr(new Error('Task has no task.file: '+
                              inspect(task.file)), cb);

  if (!is.array(task.args))
    return asyncerr(new Error('Task has no args: '+inspect(task)), cb);

  task.fileName = path.normalize(task.fileName);

  // we want to dump the file in /tmp. If it is starts with /tmp, fine.
  if (task.fileName.substr(0,4) !== '/tmp')
    task.fileName = path.join('/tmp', task.fileName);

  // get the dir and make the directory
  var dir = path.dirname(task.fileName);

  // place the output buffers in an object, so we can pass the object
github strongloop / supercluster / lib / WorkerRunFile.js View on Github external
exports.writeFile = function(fileName, fileContents, cb) {

  if (!is.nonEmptyStr(fileName)) {
    return asyncerr(new Error('writeFile: bad fileName param: '+
                              inspect(fileName)), cb);
  }

  if (!is.nonEmptyStr(fileContents) && !is.buffer(fileContents)) {
    return asyncerr(new Error('writeFile: bad fileName param: '+
                              inspect(fileName)), cb);
  }

  fs.writeFile(fileName, fileContents, function (err) {
    if (err)  {
      debug('writeFile, could not write file: '+err.message);
      return cb('writeFile, could not write file: '+err.message);
    }
    if (is.func(cb))  cb(null);
  });
};
/**

is2

A type checking library where each exported function returns either true or false and does not throw. Also added tests.

MIT
Latest version published 2 years ago

Package Health Score

68 / 100
Full package analysis