Tag: stream

Node.JS数据inputstream

有一个inputstream扩展,所以我可以调用像我习惯的方法 例如 stdin.readData(function (err, buffer) { // err if an error event was created, buffer if this is just data, null to both if the end of the stream was reached. // Added bonuses would be other methods I am used to in Java // – readLine // – readFully // – readStringUtf8 // – […]

从nodejs中的stdin中读取,强行将\ r \ n转换为\ n

在我试图制作的脚本中,nodejs从stdin中读取,但是强制转换所有\ r \ n为\ n。 这导致我的另一个脚本产生不正确的结果。 有没有办法可以防止这种情况发生? 这是我用来从标准input读取的代码。 process.stdin.resume(); process.stdin.setEncoding('ascii'); process.stdin.on('data', function(chunk){ data += chunk; }) process.stdin.on('end', function(){ console.log(JSON.stringify(data)); });

高并发聊天应用程序

我目前有一个基于Web的私人聊天应用程序,进展顺利。 现在的问题是,我正在使用mysql来保存,然后得到收到的消息,这是非常低效的,我正在考虑迁移到node.js或socket.io来处理发送的私人消息。 由于我收到的stream量每天都在增长,我将很快就要处理数十个,然后数十万个连接。 我怎么能做到这一点? 我需要多个服务器吗? 或者一个强大的服务器可以处理如此巨大的连接数量? 先谢谢你。

Node.js限制stream

我正在尝试创build一个Node.js HTTP文件stream媒体服务器。 我想要做到以下几点: 发件人–HTTP POST–> HTTP –HTTP POST–> Node.js HTTP服务器<–HTTP GET–收件人 我已经使用下面的代码: var app = express(); // … app.post('/upload', function (req, res) { // Get the `req` and `res` arguments of the HTTP GET request var downloadRequest = getDownloadClientRequest(); // parse a file upload var form = new formidable.IncomingForm(); form.onPart = function (part) { if […]

我可以为mongo中的查询创build一个可拖动的光标吗?

在节点中使用mongo和mongoose,我可以像下面这样使用capped集合创build一个stream: @stream = Post.find().tailable().stream() 但是我可以用这样的查询吗? @stream = Post.find({tagged:true}).tailable().stream() 当我尝试运行上面的代码时,出现错误 MongoError: tailable cursor requested on non capped collection

从一个stream的NodeJS反序列化

我有一个问题从节点中的stream反序列化(特别是来自比特币GOX交换的定价供给)。 基本上一个大块到达,这是完整的,并validation了JSON 。 这里是代码: var gox = require('goxstream'); var fs = require('fs'); var options = { currency: 'AUD', ticker: true, depth: false }; var goxStream = gox.createStream(options); goxStream.on('data', function(chunk) { console.log(JSON.parse(chunk)); }); 当试图parsing它,我得到以下 undefined:0 ^ SyntaxError: Unexpected end of input 有任何想法吗? 我已经包括一个样本块: > {"channel": "eb6aaa11-99d0-4f64-9e8c-1140872a423d", "channel_name": > "ticker.BTCAUD", "op": "private", "origin": "broadcast", "private": > "ticker", […]

用nodejsstream来压缩文件导致内存泄漏

我试图做一些看起来很简单的事情:用一个文件名为X的文件,并创build一个gzip版本为“X.gz”。 Nodejs的zlib模块没有提供方便的zlib.gzip(infile,outfile),所以我想我会使用一个inputstream,一个输出stream和一个zlib gzipper,然后pipe它们: var zlib = require("zlib"), zipper = zlib.createGzip(), fs = require("fs"); var tryThing = function(logfile) { var input = fs.createReadStream(logfile, {autoClose: true}), output = fs.createWriteStream(logfile + ".gz"); input.pipe(zipper).pipe(output); output.on("end", function() { // delete original file, it is no longer needed fs.unlink(logfile); // clear listeners zipper.removeAllListeners(); input.removeAllListeners(); }); } 然而,每次运行这个函数,Node.js的内存占用量都会增长100kb左右。 我忘了告诉溪stream,他们应该再次自杀,因为他们不再需要了吗? 或者,有没有办法只是gzip文件,而不打扰stream和pipe道? 我尝试使用“node.js gzip一个文件”的search引擎,但它只是链接到API文档,堆栈溢出问题的gzippingstream和缓冲区,而不是如何只是gzip文件。

node.jsstreamfile upload结构化文件夹

我做我的网站使用节点和expression一个小CMS。 我想使用一个表格positng多个文件,并将这些文件存储到公共/图像/文件夹名称。 所以我已经创build了一个表单,它有两个input:1.event – 这是事件名称2.file – 这是文件inputobvisuly 现在,当pipe理员login并看到这个表单时,他正在键入他的事件名称,例如“”生日“以及与之关联的图像文件。 最后,我希望结果如下:public / / image / birthday image1 image2 image3 image4 这里是HTML: <div class="panel panel-primary spacer3"> <div class="row"> {{#if error}} <div data-alert class="alert-box"> {{error}} <a href="#" class="close">&times;</a> </div> {{/if}} <div class="small-4 medium-4 large-4 columns text-center"> <h1>פאנל ניהול</h1> </div> <form method="POST" action="/login"> <div class="row"> <div class="large-12 columns rtl"> <label>שם […]

从nodejs中执行文件,将stdin和pipe道stdout写入文件

我有这个程序(编码在C的btw …),我想从我的nodejs服务器内部调用它。 我想传递一个string到它的stdin,而redirect/pipe道它的标准输出到一个文件。 我知道process_child有一些方法来实现这种行为,所以我试过了: program = child_process.execFile('program'); fileStream = fs.createWriteStream('file.txt'); program.stdout.pipe(fileStream); program.stdin.end('hello world!'); 这行program.stdin.end("…")会引发一些错误。 它应该像echo "hellow world!" | ./program > file.txt echo "hellow world!" | ./program > file.txt //$ cat program.c #include <stdio.h> int main() { char aux[100]; scanf("%s", aux); printf("[%s]", aux); return 0; } 更新: 使用'./program'而不是'program'解决了部分问题。 更新2 使用'hellow world!\r\n'或file.txt将只是空的。 但我的程序不读\ n,它使用%s读取。 据我所知,它会读直到\ n或EOF。 例如, […]

parsingstream式JSON

我有一个工具,我正在parsingNeo4j响应并发射对象。 https://github.com/brian-gates/neo4j-stream-deserializer 我的问题: 我如何处理错误? 有没有更好的方法来处理标题比两个parsing器? 似乎是不必要的开销。 可能的错误响应如下所示: { message: 'Error explanation, … other useful info … } 完整的例子: https://gist.github.com/brian-gates/4a16e0aee13d6e549d52 成功的回应如下所示: { columns: [], results: [] } https://github.com/brian-gates/neo4j-stream-deserializer/blob/master/test/mock/neo4j_response.json