V
V
Vasily Vasilyev2018-01-28 22:59:41
Layout
Vasily Vasilyev, 2018-01-28 22:59:41

Filter by file size?

Perhaps the question is stupid, I started working with gulp recently.

gulp.task('bla', function () {
    return gulp.src('src/images/*')
/*Проверка размера файла. Больше 10кб - игнорируются*/
        .pipe(gulp.dest('build/images'));
});

A lot of files are thrown into the task ( return gulp.src('.src/images/*')), it is necessary that it processes files larger than the specified size (10kb) and copies them to ( .pipe(gulp.dest('build/images'));), and skips smaller files (NOT copied).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AleVerDes, 2018-01-30
@Basil_Dev

With gulp-custom-filter :

var gulp = require('gulp');
var filter = require('gulp-custom-filter');

gulp.task('test', function() {
    return gulp.src('src/images/*')
        .pipe(filter(function (file) { return file.stat.size > 10 * 1024; }))
        .pipe(gulp.dest('build/images'));
});

Accordingly, 10*1024 is the file size in bytes.
If the file size is more than 10kB, then its processing will be interrupted and the next .pipe() will not reach.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question