1.0.2 • Published 7 years ago
gulp-change-buffer v1.0.2
gulp-change-buffer
Edit files as buffers - with GulpJS.
- Directly access & edit a file buffer, helpful for editing binary files on the fly.
- Forked from gulp-change, but skips the conversion of buffer to string.
npm install gulp-change-buffer
Usage
var gulp = require('gulp');
var changeBuffer = require('gulp-change-buffer');
var bufferIndexOf = require('buffer-indexof');
gulp.task('change', function() {
return gulp.src('*.png')
.pipe(changeBuffer(function(buf) {
var str = 'muffins';
var i = bufferIndexOf(buf, str);
var out = new Buffer(buf.length - str.length);
buf.copy(out, 0, 0, i);
buf.copy(out, i, i + str.length, buf.length);
return out;
))
.pipe(gulp.dest('build/'));
});
Callback Context
The callback receive a custom context (this
) populated with:
file
original file object from Gulp' stream
fname
file name
originalContent
original file content