我有以下示例代码尝试将流传输到gulp.dest():
path.js:146
throw new TypeError('Arguments to path.resolve must be strings');
^
TypeError: Arguments to path.resolve must be strings
at Object.win32.resolve (path.js:146:13)
at DestroyableTransform.saveFile [as _transform] (C:\paylocity\expense\node_modules\gulp\node_modules\vinyl-fs\lib\dest\index.js:36:26)
at DestroyableTransform.Transform._read (C:\paylocity\expense\node_modules\gulp\node_modules\vinyl-fs\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:184:10)
at DestroyableTransform.Transform._write (C:\paylocity\expense\node_modules\gulp\node_modules\vinyl-fs\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:172:12)
at doWrite (C:\paylocity\expense\node_modules\gulp\node_modules\vinyl-fs\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:237:10)
at writeOrBuffer (C:\paylocity\expense\node_modules\gulp\node_modules\vinyl-fs\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:227:5)
at DestroyableTransform.Writable.write (C:\paylocity\expense\node_modules\gulp\node_modules\vinyl-fs\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:194:11)
at Readable.ondata (_stream_readable.js:540:20)
at Readable.emit (events.js:107:17)
at Readable.read (_stream_readable.js:373:10)
此代码产生以下错误:
var YAML = require('yamljs');
但是,我无法看到代码到底出了什么问题。如果我用process.stdout替换gulp.dest()然后它工作,gulp.dest()在其他调用的上下文中工作。这样做的可行方法是什么?
答案 0 :(得分:6)
Gulp与乙烯基流合作:
var gulp = require('gulp'),
stream = require('stream'),
source = require('vinyl-source-stream');
var readable = new stream.Readable;
readable.push('Hello, world!');
readable.push(null);
readable
.pipe(source('test.txt'))
.pipe(gulp.dest('.'));
Gulp流通常是begins with some file or files as source,因此您需要将该可读流包装到Vinyl stream中,允许Gulp和任何gulp-plugin从文件名中获取信息(显然是假的),避免错误你的。
因此,Gulp流是文件流,只是check the source ...