如何读取流 .pipe(myfunction())
How read stream .pipe(myfunction())
如何读取流.pipe(myfunction())?
我尝试,但给出错误。如何读取gulp.src('./userdata.json')和.pipe()的流?我不知道它是怎么做到的。
古尔普文件.js
var upmodul = require("modul-json");
//......
return gulp.src('./userdata.json')
.pipe(upmodul());
......//
node_modules/modul-json/index.js
'use strict';
var Stream = require('stream');
var loger = function () {
var readable = new Stream.Readable({
read: function (n) {
this.push("ll");
}
});
}
module.exports = loger;
错误
[00:19:39] TypeError: Cannot read property 'on' of undefined
at DestroyableTransform.Readable.pipe (E:'Developers'WebDeveloper'OpenServer
-WebProg'domains'progectapi2'node_modules'vinyl-fs'node_modules'readable-stream'
lib'_stream_readable.js:516:7)
at Gulp.<anonymous> (E:'Developers'WebDeveloper'OpenServer-WebProg'domains'p
rogectapi2'gulpfile.js:159:9)
at module.exports (E:'Developers'WebDeveloper'OpenServer-WebProg'domains'pro
gectapi2'node_modules'orchestrator'lib'runTask.js:34:7)
at Gulp.Orchestrator._runTask (E:'Developers'WebDeveloper'OpenServer-WebProg
'domains'progectapi2'node_modules'orchestrator'index.js:273:3)
at Gulp.Orchestrator._runStep (E:'Developers'WebDeveloper'OpenServer-WebProg
'domains'progectapi2'node_modules'orchestrator'index.js:214:10)
at Gulp.Orchestrator.start (E:'Developers'WebDeveloper'OpenServer-WebProg'do
mains'progectapi2'node_modules'orchestrator'index.js:134:8)
at C:'Users'Tiki
'AppData'Roaming'npm'node_modules'gulp'bin'gulp.js:129:20
at nextTickCallbackWith0Args (node.js:433:9)
at process._tickCallback (node.js:362:13)
at Function.Module.runMain (module.js:432:11)
gulp 文档包含一些有关构建可能对您有用的插件的信息。该页面中的一个示例讨论了转换流。
所有 gulp 插件基本上都归结为:
var Transform = require('stream').Transform; module.exports = function() { // Monkey patch Transform or create your own subclass, // implementing `_transform()` and optionally `_flush()` var transformStream = new Transform({objectMode: true}); /** * @param {Buffer|string} file * @param {string=} encoding - ignored if file contains a Buffer * @param {function(Error, object)} callback - Call this function (optionally with an * error argument and data) when you are done processing the supplied chunk. */ transformStream._transform = function(file, encoding, callback) { var error = null, output = doSomethingWithTheFile(file); callback(error, output); }); return transformStream; };
相关文章:
- 为什么$.when().pipe().then()有效,而$.when
- ondblclick myfunction()不会激发
- pipe() 和 then() 文档与 jQuery 1.8 中的现实
- 将.pipe()流到node.js中的一个变量
- window.myFunction不起作用
- 在Node.js网络中使用pipe()
- Separate pipe() and $.Deferred.resolve()
- .click(function () { 和 javascript:myfunction() 有什么区别?
- 如何在node中编写事件发射器.js让你创建一个函数“myFunction”,然后在运行时调用成功或失败
- jsHint “myFunction 已定义但从未使用过”
- 如何编写一个简单的 gulp pipe函数
- 首先读取数据以决定在哪里使用 .pipe()
- jquery 函数 onclick 和 onload myFunction 不是一个函数
- Deferred.pipe() 可以防止调用后续的 .done 和 .fail 吗?
- 引用错误:未定义 myfunction
- gulpfile.js 中意外的令牌 .pipe
- window.addEventListener('message', myFunction(event)
- ps au |grep ssh 在 Node.js (使用 spawn/pipe) 与 shell 中不同
- 未捕获的语法错误:意外的标记<和未捕获的引用错误:未定义 myFunction
- 如何读取流 .pipe(myfunction())