how get file size in bytes through gulp task

I have an APK file in my source folder and I just want to get the size of that file (in bytes) with a gulp task and update that size in an XML file.

Below is my gulp task:

gulp.task('geteditmscript', function(){
    gulp.src("source/deployment.xml")
        .pipe(xeditor([
            {path: '//SCRIPT', attr: {'revision': json.version}},
            {path: '//APP', attr: {'size': gulp.src('source/*.apk').pipe(size())}}
        ]))
        .pipe(gulp.dest("source/"));
});

Answers


Your code doesn't work because gulp.src('source/*.apk').pipe(size()) doesn't return a file size. It returns a stream.

And while gulp-size gives you access to the total size of all files via its .size property this is only available after all files have been processed.

That means you need to delay your xeditor() stream until after the size() stream has finished. You can do that by placing it into an on('finish', ...) handler:

gulp.task('geteditmscript', function(cb) {

  var apkSize = size();

  gulp.src('source/*.apk')
    .pipe(apkSize)
    .on('finish', function() {

      gulp.src("source/deployment.xml")
        .pipe(xeditor([
          {path: '//SCRIPT', attr: {'revision': json.version}},
          {path: '//APP', attr: {'size': apkSize.size }}
        ]))
        .pipe(gulp.dest("source/"))
        .on('end', cb);

    });
});

Need Your Help

Xamarin.IOS: UITableViewSource crashes on device

c# ios iphone uitableview xamarin

I've a very simple app which contains only UITableView and its UITableViewSource..

How posix system support unicode?

c api unicode posix

I have seen a lot of API posix system, for example Linux & Mac & android, which accept const char* as the argument for file path.