W3C home > Mailing lists > Public > public-webapps@w3.org > July to September 2013

Re: Overlap between StreamReader and FileReader

From: Aymeric Vitte <vitteaymeric@gmail.com>
Date: Thu, 22 Aug 2013 13:20:40 +0200
Message-ID: <5215F408.7030403@gmail.com>
To: Jonas Sicking <jonas@sicking.cc>
CC: Isaac Schlueter <i@izs.me>, Austin William Wright <aaa@bzfx.net>, Domenic Denicola <domenic@domenicdenicola.com>, Takeshi Yoshino <tyoshino@google.com>, "public-webapps@w3.org" <public-webapps@w3.org>


Le 22/08/2013 09:28, Jonas Sicking a écrit :
> Does anyone have examples of code that uses the Node.js API? I'd love
> to look at how people practically end up consuming data?
I am doing something like this:

var parse=function() {
     //process this.stream_
     this.queue_.shift();
     if (this.queue_.length) {
         this.queue_[0]();
     };
};
var process=function(data) {
     return function() {
         this.stream_=[this.stream_,data].concatBuffers();
         parse.call(this);
     };
};
var on_data=function(data) {
     this.queue_=this.queue_||[];
     this.queue_.push(process(data).bind(this));
     if (this.queue_.length===1) {
         this.queue_[0]();
     };
};
request.on('data',function(data) {
     on_data.call(this,data);
});

I don't remember exactly if it's due to my implementation or node 
(because I am using both node's Buffers and Typed Arrays) but I 
experienced some problems where data was modified while it was being 
processed, that's why this.stream_ is freezing the data received (with 
remaining bytes received earlier, see next sentence) until it is processed.

Coming back to my previous TextEncoder/Decoder remark for utf-8 parsing, 
I don't know how to do this with native node functions.

Regards

Aymeric

-- 
jCore
Email :  avitte@jcore.fr
iAnonym : http://www.ianonym.com
node-Tor : https://www.github.com/Ayms/node-Tor
GitHub : https://www.github.com/Ayms
Web :    www.jcore.fr
Extract Widget Mobile : www.extractwidget.com
BlimpMe! : www.blimpme.com
Received on Thursday, 22 August 2013 11:21:24 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:14:12 UTC