Tag: 包pipe理器

nodejspipe道https响应request.post和写入文件

我正在做HTTP代理程序,检查HTTP URL,如果它是下载链接(内容types:八位字节stream),我会得到响应,并通过使用request.post和其他计算机下载文件与其他计算机响应中继该响应由http代理给出。 假设networking代理计算机是A.并且它是A. 192.168.5.253的代码的一部分 if(contentType && (contentType== "application/octet-stream" || contentType == "application/gzip")){ console.log("remoteRes##app",remoteRes); let filepath = req.url.split('/'); let FileName = getFilename(remoteRes, filepath); let writeStream = fs.createWriteStream(FileName); /*remoteRes is octect-stream response. I can get file buffer If I use remoteRes.on(data, chunk => {…})*/ remoteRes.pipe(writeStream); //It works but I want to send file buffer to B without […]

pipe道不被subprocess读取?

我想运行node.js作为一个subprocess并为其提供input。 使用C,这里是我的一些示例代码。 我遇到的问题是,尽pipesubprocess的stdout仍然是针对terminal的,但是在给subprocess标准input一个'Hello World'行后,我什么也看不到。 即使我()pipe道,我没有看到输出。 但是,如果我closures了pipe道的input,那么terminal上会出现“Hello World”。 subprocess似乎只是缓冲 – 为什么呢? 我想最终将subprocessstdoutredirect到另一个pipe道,并从main()中读取它。 int main(int argc,char * argv []){ int toNode[2]; pipe(toNode); pid_t child_pid = fork(); if (child_pid == 0) { // child // close write end close(toNode[1]); // connect read end to stdin dup2(toNode[0], STDIN_FILENO); // run node executable char* arg_list[] = { "/usr/bin/node", NULL}; execvp(arg_list[0], […]

bash和javascript之间的消息通过命名pipe道

我有一个JavaScript应用程序需要启动一个Linux应用程序。 由于我没有find任何方式来启动应用程序,当它结束时,我做了一个bash脚本启动应用程序,并在应用程序closures时通过命名pipe道发送消息。 直到这里,一切都很好,但是我找不到在javascript中捕获这个消息的方法。 有人知道如何获得在JavaScript的消息? 我search了,但我只发现如何在C#和C ++中做到这一点。 来自javascript的示例: var test = spawn('sh', ['home/pi/play.sh', data.video_id]); 只是产生一个bash命令,以video的名称启动脚本 来自bash的示例: mkfifo btjpipe if pgrep omxplayer then echo "AR">btjpipe else clear omxplayer $1 > dev/null echo "VE">btjpipe 创buildpipe道,寻找玩家是否已经在运行,然后发送AR(“已经运行”)或启动播放器并发送VE(“Video End”)。

Node.js套接字pipe道方法不会pipe最后一个数据包到http响应

我有使用Express作为networking应用程序的节点服务器。 此服务器与另一端TCP服务器创build一个tcp套接字连接。 我正在尝试将tcp数据传递给用户http响应。 它工作正常,但最后的tcp数据包没有pipe道http响应。 所以,下载的网页浏览器下载状态为99.9%。 我的源代码如下。 任何人都可以帮我解决这个问题? 提前致谢。 app.get('/download/*', function(req, res){ var tcpClient = new net.Socket(); tcpClient.connect(port, ip, function() { // some logic }); tcpClient.on('data', function(data) { /* skip … */ tcpClient.pipe(res); // This method is called once in the 'data' event loop /* skip … */ }); tcpClient.on('close', function() { clog.debug('Connection closed.'); }); tcpClient.on('end', […]

使用请求从url下载图像并保存到variables

有没有办法我可以从请求下载图像并将其保存到variables? request.head(url, function(err, res, body){ request(url).pipe(fs.createWriteStream(image_path)); }); 现在我将结果输送到写入stream。 但是,我想将其保存到一个variables,所以我可以在我的程序中使用它。 有没有办法做到这一点?

Netbeans和nodejs使用

您好我正在NetBeans IDE中创buildnodejs应用程序。 每次当我更改js文件我需要手动重新启动服务器。 你知道如何自动部署?

指定由节点中的hubot创build的GET请求的callback函数

我们当地的Hubot(“Sparky”)运行大量的插件脚本,并且一般运行良好。 我正在写一个插件脚本,对Yahoo Pipes进行GET调用,并期待JSONP的结果。 但是,我不确定如何使用_callback参数。 码: module.exports = (robot) -> robot.hear /\bkeyword\b/i, (msg) -> robot.http("http://pipes.yahoo.com/pipes/pipe.run") .query({ _id: "legit-pipe-id-is-here", _render: "json", _callback: "?" }) .get() (err, res, body) -> if body? data = JSON.parse(body) 这得到的错误是: undefined:1 _({"count":10,"value":{"title":"correct title","description":"Pipes Output","lin ^ SyntaxError: Unexpected token _ at Object.parse (native) at e:\node\sparky\scripts\plugin-name.coffee:26:11, <js>:11:23 at IncomingMessage.<anonymous> (e:\node\sparky\node_modules\hubot\node_modules\scoped-http-client\lib\index.js:70:20) at IncomingMessage.EventEmitter.emit (events.js:117:20) at […]

如何通过pipe道控制node.js中httpstream的stream动

正如Node.js开发人员所知道的,节点可以将stream传输到另一个资源,如http响应。 解决scheme#1 http.createServer(function (req, res) { stream = fs.createReadStream(filename); stream.pipe(res); }); 解决scheme#2 还有另外一种方法来控制不需要pipe道的stream和缓冲区响应stream http.createServer(function (req, res) { stream = fs.createReadStream(filename); stream.on('data', function(data) { if (res.write(data) == false){ stream.pause(); } }); stream.on('end', function(data) { res.end(); }); res.on('drain', function(data) { stream.resume(); }); }); 解决scheme#2比#1好吗? 我认为这样更好,因为我们可以控制stream向http响应的stream。 当响应缓冲区满并且stream不能写入数据时,stream将暂停,并且当响应成为排放stream时将恢复 我的问题 当我使用解决scheme#2时,我的节点应用程序将停止工作站而不响应其他客户端。 这意味着它一次只能服务于一个客户! 我觉得这个问题会发生,因为节点正在等待发送res.end()到客户端并结束响应。 但我不明白如何解决这个问题。 如果这个解决scheme是绝对错误的,我只需要使用stream.pipe()请告诉我如何使用resume和pause函数来控制pipe道的stream动

错误:find无效的caching选项true。 预期的“记忆”

这个错误显示在cmd使用rhc tail socialinteractive我主持这个网站openshfit我使用swig和模块巩固和摆动的模板指导我解决这个错误 Error: Invalid cache option true found. Expected "memory" or { get: function (ke y) { … }, set: function (key, value) { … } }. at validateOptions (/var/lib/openshift/5453580c500446bfbc000d3c/app-root/run time/repo/node_modules/swig/lib/swig.js:113:15) at parse (/var/lib/openshift/5453580c500446bfbc000d3c/app-root/runtime/repo/ node_modules/swig/lib/swig.js:339:5) at Object.precompile (/var/lib/openshift/5453580c500446bfbc000d3c/app-root/r untime/repo/node_modules/swig/lib/swig.js:486:23) at Object.compile (/var/lib/openshift/5453580c500446bfbc000d3c/app-root/runt ime/repo/node_modules/swig/lib/swig.js:606:16) at Function.exports.swig.render (/var/lib/openshift/5453580c500446bfbc000d3c /app-root/runtime/repo/node_modules/consolidate/lib/consolidate.js:246:56) at /var/lib/openshift/5453580c500446bfbc000d3c/app-root/runtime/repo/node_mo dules/consolidate/lib/consolidate.js:146:25 at read (/var/lib/openshift/5453580c500446bfbc000d3c/app-root/runtime/repo/n ode_modules/consolidate/lib/consolidate.js:91:22) […]

在NodeJS中pipe理两个命令

我需要将一个CLI转换为nodejs中的“spawn”语法,而我陷入了一丝混乱,无法从文档中找出如何处理它。 语法是这样的: somecommand -a op1 -b op2 | othercommand -c op1 -d op2 “其他命令”应该从“somecommand”输出“live”。 我想监视“othercommand”的输出。 谢谢,Tal。