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 : avi...@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