Coder Social home page Coder Social logo

npm-verify-stream's Introduction

npm-verify-stream

A duplex stream for receiving a package tarball, verifying arbitrary checks, and emitting that same tarball on success.

Usage

var VerifyStream = ('npm-verify-stream');
var fs = require('fs');
var request = require('request');

//
// Create our verifier
//
var verifier = new VerifyStream({
  log: console.log,
  checks: [
    //
    // A set of checks to run on a fully read npm package
    // See [Checks] below.
    //
  ]
});

//
// Put the tarball somewhere (like npm) ONLY if it passes
// all of the checks.
//
fs.createReadStream('npm-verify-stream-0.0.0.tgz')
  .pipe(verifier)
  .pipe(request.post('https://registry.nodejitsu.com/npm-verify-stream'));

Checks

A "check" is a function that accepts an npm-package-buffer and responds with either no error or an error indicating how the package violated the check.

example-check.js

module.exports = function (version, done) {
  //
  // `version.package` is a fully JSON parsed the package.json.
  //
  console.dir(version.package);

  //
  // `version.files` is all files read into memory
  //
  console.dir(version.files);

  //
  // Respond when done
  //
  done();
};

API

See also: npm-package-buffer, tar-buffer.

Options

  • checks: (required) Check functions that must pass to consider the package verified.
  • concurrency: (default: 5) Number of concurrent checks to run.
  • log: (optional) Log function to use. Expects console.log API.
  • read: (optional) Options to pass to the TarBuffer.
  • before: (optional) Stream to pipe to BEFORE piping to the zlib.Unzip and tar.Parse streams.
  • cleanup: (optional) If explicitly set to false then temporary files will not be cleaned up. Useful for debugging.

Events

  • error: as with any stream these will be emitted if the readable or writable end of the duplex stream has errored. It will also be emitted if there is an error writing the tarball to the disk cache during the verification process or if the verification fails.
  • cleanup: emitted when the cached tarball is removed.
verifier.on('cleanup', function (file, err) {
  // If there was an error removing from your cache
  // it will be here. ENOENT errors are ignored.
});
LICENSE: MIT

npm-verify-stream's People

Contributors

indexzero avatar

Stargazers

Jerzerak avatar Martijn Swaagman avatar Jarrett Cruger avatar

Watchers

 avatar Fady Matar avatar Jarrett Cruger avatar  avatar

Forkers

swaagie

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.