T
T
thehighhomie2016-10-08 23:10:46
Node.js
thehighhomie, 2016-10-08 23:10:46

Gulp: Why doesn't a file have an extname property in stream?

I watch screencasts by I. Kantor on Gulp. Why don't I have it in the screencast, in the stream, the file doesn't have an extname?
Here is gulpfile.js code:

'use strict';

var gulp = require('gulp');

gulp.task('default', function() {
  return gulp.src('source/**/*.*').
    on('data', function(file) {
      console.dir(file.extname);
    })
});

and here is the output in the console:
[23:09:37] Using gulpfile ~\Desktop\gulp\project\gulpfile.js
[23:09:37] Starting 'default'...
undefined
undefined
[23:09:37] Finished 'default' after
22 ms
gulp.task('default', function() {
  return gulp.src('source/**/*.*').pipe(gulp.dest(function(file) {
    console.dir(file.extname);
    return 'dest';
  }));
});

and this is what the console outputs:
[23:22:01] Using gulpfile ~\Desktop\gulp\project\gulpfile.js
[23:22:01] Starting 'default'...
File {
history: [ 'C:\\ Users\\rain-\\Desktop\\gulp\\project\\source\\1\\1.css' ],
cwd: 'C:\\Users\\rain-\\Desktop\\gulp\\project' ,
base: 'C:\\Users\\rain-\\Desktop\\gulp\\project\\source\\',
stat:
{ dev: -2041281915,
mode: 33206,
nlink: 1,
uid: 0,
gid : 0,
rdev: 0,
blksize: undefined,
ino: 2251799813836494,
size: 36,
blocks: undefined,
atime: 2016-10-08T19:30:35.000Z,
mtime: 2016-10-08T19:45:27.000Z,
ctime: 2016-10-08T19:45:27.665Z,
birthtime: 2016-10-08T19:30:35.357Z },
_contents:
Buffer [
98,
111,
100,
121,
32,
123,
13,
10,
32,
32 ,
98,
97,
99,
107,
103,
114,
111,
117,
110,
100,
45,
99,
111,
108,
111,
114,
58,
32,
35,
102,
102,
102,
59,
13,
10,
125 ] }
File {
history: [ 'C:\\Users\\rain-\\Desktop\\gulp\\project\\source\\1\\1.js' ],
cwd : 'C:\\Users\\rain-\\Desktop\\gulp\\project',
base: 'C:\\Users\\rain-\\Desktop\\gulp\\project\\source\\',
stat:
{ dev: -2041281915,
mode: 33206,
nlink: 1,
uid: 0,
gid: 0,
rdev: 0,
blksize: undefined,
ino: 3940649674100336,
size: 18,
blocks: undefined,
atime: 2016-10- 08T19:30:03.000Z,
mtime: 2016-10-08T19:45:29.000Z,
ctime: 2016-10-08T19:45:29.373Z,
birthtime: 2016-10-08T19:30:03.568Z },
_contents:
Buffer [
118,
97,
114,
32,
110,
97,
109,
101,
32,
61,
32,
39,
77,
105,
107,
101,
39,
59 ] }
[23:22:01] Finished 'default' after 52 ms
That is, file has only 5 properties, these are history, cwd, base, stat and Buffer. Properties realative, extname does not even smell.
Why don't I have this? Ilya has it in the screencast. Maybe because of the version? He put the fourth version, I'll help you with 3.9.1.
What's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2016-10-08
@thehighhomie

gulp.task('default', function() {
  return gulp.src('source/**/*.*').pipe(gulp.dest(function(file) {
    console.log(file.extname);
    return 'dest';
  }));
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question