Permalink
Browse files

fix writeHead, fix date object

  • Loading branch information...
1 parent ccbf34d commit 3b1b6558f091c869d2dae6e247045bd2690000cb @async-cl async-cl committed Jul 30, 2012
Showing with 427 additions and 4 deletions.
  1. +3 −0 Makefile
  2. +128 −0 Test.hx
  3. +6 −0 build.hxml
  4. +12 −4 js/Node.hx
  5. +278 −0 js/oldBoot.hx
View
@@ -0,0 +1,3 @@
+
+all:
+ haxe build.hxml
View
128 Test.hx
@@ -0,0 +1,128 @@
+
+import js.Node;
+
+import haxe.io.Eof;
+import haxe.io.Bytes;
+import haxe.io.BytesBuffer;
+import haxe.io.BytesInput;
+import haxe.io.BytesData;
+
+import js.node.AsyncReader;
+
+import js.node.AsyncPositionReaderImpl;
+import js.node.AsyncStreamReaderImpl;
+
+//using haxe.aio.File;
+
+
+enum ReaderType {
+ Stream;
+ Seek;
+
+}
+
+class MyFile {
+
+ public static function
+ asyncReader(type:ReaderType,file:String,?bufSize:Int,cb:AsyncReader->Void) {
+ return switch(type) {
+ case Seek:
+ new AsyncPositionReaderImpl(file,bufSize).open(cb);
+ case Stream:
+ new AsyncStreamReaderImpl(file,bufSize).open(cb);
+ }
+ }
+}
+
+
+using Lambda;
+
+class Test {
+
+ public static function
+ main() {
+
+ trace(js.Node.process.arch);
+ // trace("newSocket:"+js.Node.newSocket().connect(80,"cloudshift.cl"));
+
+ var b = new NodeBuffer(20);
+ b.fill("A".charCodeAt(0),0);
+ trace(b.toString(NodeC.UTF8));
+
+ var b2 = new NodeBuffer("To be or not to be",NodeC.UTF8);
+ trace(b2.toString(NodeC.UTF8));
+
+ var s = "that is the question";
+ var arr = [];
+ for (c in 0...s.length) arr.push(s.charCodeAt(c));
+
+ var b3 = new NodeBuffer(arr);
+ trace(b3.toString(NodeC.UTF8));
+
+ var file = "README";
+ var myBuff = new BytesBuffer();
+
+#if true
+ MyFile.asyncReader(Seek,file,10,function(ar) {
+ ar.onEof(function() {
+ trace(myBuff.getBytes().toString());
+ ar.seek(0);
+ trace("--------------------------");
+ var mybuf = Bytes.alloc(100);
+ ar.readBuffer(mybuf,0,100,function(nr) {
+ trace("I read :"+nr);
+ trace(mybuf.toString());
+ });
+ });
+ recur(ar,myBuff);
+ });
+ #else
+ MyFile.asyncReader(Stream,file,100,function(ar) {
+ ar.readBytesInput(function(nr,bytes) {
+ trace(bytes.readAll());
+ //trace("bytes :"+bytes.length+" -> "+bytes.toString());
+ })
+ .onEof(function() {
+ trace("OK GOT END");
+ ar.close();
+ });
+ });
+ #end
+
+ /*
+ js.node.File.readStream(file,100)
+ */
+
+ /*
+ file.stream().toBuffer(Bytes.alloc(50),0,50,function(bytes,nr) {
+ trace("Read:"+nr+", "+bytes.toString());
+ }).onSuccess(function() {
+ trace("nice one I've finished");
+ }).onFailure(function(err) {
+
+ });
+
+ file.read(function(input) trace(input.readAll()));
+ file.copy("NEWREADME").onSuccess(function() trace("finished copying"));
+ file.getBytes(function(bytes) {
+
+ });
+
+ file.getContent(function(content) {
+
+ });
+
+ */
+
+ }
+
+ static function recur(pr:AsyncReader,myBuff:BytesBuffer) {
+ pr.readBytes(function(bytes) {
+ trace(pr.tell()+":"+bytes.length);
+ myBuff.addBytes(bytes,0,bytes.length);
+ recur(pr,myBuff);
+ });
+
+ }
+
+}
View
@@ -0,0 +1,6 @@
+
+-cp .
+-D nodejs
+-main Test
+-js test.js
+-cmd node test.js
View
@@ -217,6 +217,13 @@ typedef NodeOs = {
function networkInterfaces():Dynamic;
}
+
+typedef NodeJsDate = {
+ function getTime():Int;
+ function toDateString():String;
+ function toUTCString():String;
+}
+
typedef NodeStat = {
var dev:Int;
var ino:Int;
@@ -228,9 +235,9 @@ typedef NodeStat = {
var size:Int;
var blkSize:Int;
var blocks:Int;
- var atime:String;
- var mtime:String;
- var ctime:String;
+ var atime:NodeJsDate;
+ var mtime:NodeJsDate;
+ var ctime:NodeJsDate;
function isFile():Bool;
function isDirectory():Bool;
@@ -543,7 +550,8 @@ typedef NodeHttpServerReq = { >NodeEventEmitter,
typedef NodeHttpServerResp = { > NodeWriteStream,
var statusCode:Int;
function writeContinue():Void;
- function writeHead(statusCode:Int,?reasonPhrase:String,?headers:Dynamic):Void;
+ @:overload(function(statusCode:Int,?reasonPhrase:String,?headers:Dynamic):Void {})
+ function writeHead(statusCode:Int,headers:Dynamic):Void;
function setHeader(name:String,value:Dynamic):Void;
function getHeader(name:String):Dynamic;
function removeHeader(name:String):Void;
Oops, something went wrong.

0 comments on commit 3b1b655

Please sign in to comment.