robrich / gulp-ignore

plugin for gulp to ignore files in the stream based on file characteristics
MIT License
121 stars 10 forks source link

Filtering by Filesize #5

Closed rafaelfaria closed 9 years ago

rafaelfaria commented 9 years ago

I'm trying to filter some files by it's filesize but i'm getting some errors:

I'm trying to check if the file has some content in it (because sometimes it doesnt)

var isThereContent = function(file) {
    var fileStat = fs.fstatSync(file);

       if (fileStat.size > 1000) {
            return true;
       } else {
              return false;
       }
}
gulp.src(config.directory.src)
        .pipe(gulpIgnore.include(isThereContent))
        .pipe(rename(renameFiles))
        .pipe(gulp.dest(config.directory.dest));

I get the following error:

  return binding.fstat(fd);
                 ^
TypeError: Bad argument
    at Object.fs.fstatSync (fs.js:674:18)

Would you be able to help?

robrich commented 9 years ago

File isn't the filename but rather a vinyl-fs file object, which has on it a stat prop. See https://github.com/wearefractal/vinyl-fs/blob/master/lib/src/index.js#L39

rafaelfaria commented 9 years ago

I used the following function

var isThereContent = function(file) {

    var fd = fs.openSync(file.path, "r"),
        fileStat = fs.fstatSync(fd);

    if (fileStat.size > 50) {
        return true;
    } else {
        return false;
    }
}
robrich commented 9 years ago

var isThereContent = function(file) { return (file.stat.size > 50); }