This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var util = require('util'); | |
var http = require('http'); | |
var stream = require('stream'); | |
var crypto = require('crypto'); | |
var server = http.createServer(); | |
server.on('request', function(request, response) { | |
response.writeHead(200, { "Content-Type": "text/plain" }); | |
response.end('Hello World\n'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var stream = require('stream'); | |
var rOne = new stream.Readable(); | |
var rTwo = new stream.Readable(); | |
rTwo.isBody = false; | |
rTwo.source = rOne; | |
rOne._read = function() {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var util = require('util'); | |
var http = require('http'); | |
var crypto = require('crypto'); | |
var server = http.createServer(); | |
server.on('request', function(request, response) { | |
response.writeHead(200, { "Content-Type": "text/plain" }); | |
response.end('Hello World'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var util = require('util'); | |
var stream = require('stream'); | |
var parser = new stream.Readable(); | |
var source = new stream.Readable(); | |
parser.cache = []; | |
parser.source = source; | |
parser._read = function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for small text messages | |
wsserver.on('message', function(message, wssocket) { | |
wsserver.broadcast(message); | |
}); | |
// for large, fragmented messages | |
wsserver.on('stream', function(request, response) { | |
response.select([2, 4, 5]); | |
request.pipe(response); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <v8.h> | |
#include <node.h> | |
#include <node_buffer.h> | |
#include <iostream> | |
using namespace v8; | |
Handle<Value> CalcHeadSize(const Arguments &args) { | |
HandleScope scope; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <v8.h> | |
#include <node.h> | |
#include <node_buffer.h> | |
using namespace v8; | |
Handle<Value> CreateBuffer(const Arguments &args) { | |
HandleScope scope; | |
char chunk[4]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "parser.h" | |
Handle<Value> CalcHeadSize(const Arguments &args) { | |
HandleScope scope; | |
Local<Object> object = args[0]->ToObject(); | |
if (node::Buffer::HasInstance(object)) { | |
if (node::Buffer::Length(object) < 2) { | |
ThrowException(Exception::TypeError( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <v8.h> | |
#include <node.h> | |
inline Local<Value> ThrowTypeError(const char* message) { | |
HandleScope scope; | |
ThrowException(Exception::TypeError(String::New(message))); | |
return scope.Close(Undefined()); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <v8.h> | |
#include <node.h> | |
#include <node_buffer.h> | |
using namespace v8; | |
typedef unsigned char byte; | |
Handle<Value> ReturnBufferWithCAllocatedMemory(const Arguments &args) { | |
HandleScope scope; |
OlderNewer