npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-vinyl-md5

v0.0.1

Published

Extract md5 hashes from vinyl-file contents.

Downloads

529

Readme

gulp-vinyl-md5 Build Status

Extract md5 hashes from vinyl-file contents

Install

$ npm install --save-dev gulp-vinyl-md5

The module provides two utility methods getMd5Value(file) and getMd5Promise(file) that can be used by plugin authors as a common way of extracting MD5 hashes.

It also provides a gulp plugin that can cache the MD5 hash at an earlier point in the stream. Neither utility method requires that the plugin be used, however, using the plugin will cache the MD5 hash at that particular point in the stream.

var gulp = require('gulp');
var gzip = require('gulp-gzip');
var vinylMd5 = require('gulp-vinyl-md5');

gulp.src('./someFile.txt')
  .pipe(gzip())
  .pipe(through.obj(function(file, enc, next) {
    // retrieves md5 hash at the current point, AFTER the `gzip()` transform
    vinylMd5.getMd5Value(file);
  }));  
  
gulp.src('./someFile.txt')
  .pipe(vinylMd5()) // cache the md5 value
  .pipe(gzip())
  .pipe(through.obj(function(file, enc, next) {
    // retrieves md5 hash at the cache point, BEFORE the `gzip()` transform.
    vinylMd5.getMd5Value(file);  
  }));  

If you only support Buffers, you should use getMd5Value(file) since it is synchronous.

API

vinylMd5()

Provides a pipe-able duplex stream that caches the md5 value for use by downstream plugins. It does not change the contents of the file.

vinylMd5.getMd5Value(file)

For Buffers only. Returns the MD5 hash of the file contents. If the vinylMd5() plugin was used upstream, it returns the MD5 hash of the contents at the point where the plugin was inserted into the stream, otherwise it returns the MD5 hash of the contents at the current point.

vinylMd5.getMd5Promise(file)

Similar to getMd5Value(file), but it returns an asynchronously resolved promise. It has the added benefit of working with Streams. If your plugin depends on the md5 hash to perform stream manipulation, you may need to buffer some/all of the stream until the promise resolves.

Behind the scenes

The vinylMd5() plugin caches the results on one of two variables (md5Value or md5Promise):

var gulp = require('gulp');
var vinylMd5 = require('gulp-vinyl-md5');
var through = require('through2');

gulp.task('with-buffers', function () {
	return gulp.src('src/file.ext')
		.pipe(vinylMd5())
		.pipe(through.obj(function(file, enc, next) {
			// md5 hash is on the file object.
			console.log(file.md5Value);
			this.push(file);
			next();
		}))
		.pipe(gulp.dest('dist'));
});

gulp.task('with-streams', function () {
	return gulp.src('src/file.ext', {buffer: false})
		.pipe(vinylMd5())
		.pipe(through.obj(function(file, enc, next) {
			// for streams it provides a promise that resolves when the stream completes.
			file.md5Promise.then(function(md5) {
			  console.log(md5);
			});
			this.push(file);
			next();
		}))
		.pipe(gulp.dest('dist'));
});

License

MIT © James Talmage