Exemple #1
0
    it("readline", () => {
        f = fs.openFile(path.join(__dirname, "test0000" + base_port));
        var r = new io.BufferedStream(f);
        r.EOL = '\r\n';

        var n = 0;
        var s1;

        while ((s1 = r.readLine()) !== null) {
            assert.equal('0123456789', s1);
            n++;
        }
        assert.equal(8192, n);
        f.close();

        f = fs.openFile(path.join(__dirname, "test0000" + base_port));
        var r = new io.BufferedStream(f);
        r.EOL = '\r\n';

        assert.equal(r.readLine(10), '0123456789');
        assert.throws(() => {
            r.readLine(9);
        });

        f.close();
    });
Exemple #2
0
		function get_response(txt) {
			var ms = new io.MemoryStream();
			var bs = new io.BufferedStream(ms);
			bs.EOL = "\r\n";

			bs.writeText(txt);
			ms.seek(0, fs.SEEK_SET);

			var req = new http.Response();
			req.readFrom(bs);
			return req;
		}
Exemple #3
0
	return function() {
		var conn = new io.BufferedStream(net.connect("127.0.0.1", arguments[0]));
		var jss = [];
		jss.push('{"method":"');
		jss.push(method);
		jss.push('","params":');
		jss.push(JSON.stringify(Array.prototype.slice.call(arguments, 1)));
		jss.push("}");
		var ps = new Buffer(jss.join(""));
		conn.writePacket(ps);
		var result = JSON.parse(conn.readPacket()).result;
		conn.close();
		return result;
	}
Exemple #4
0
		function get_request(u) {
			var ms = new io.MemoryStream();
			var bs = new io.BufferedStream(ms);
			bs.EOL = "\r\n";

			bs.writeText(u);
			ms.seek(0, fs.SEEK_SET);

			var r = new http.Request();

			r.readFrom(bs);

			return r;
		}
Exemple #5
0
    function t_read(f, sz) {
        var r = new io.BufferedStream(f);
        var p = 0;
        var d;

        while (p < s.length) {
            d = r.read(sz);
            if (!d)
                break;
            assert.equal(d.toString(), s.substring(p, p + sz));
            p += sz;
        }
        f.close();
    }
Exemple #6
0
	it("PacketHandler", function() {
		var s = new net.TcpServer(9876, new mq.PacketHandler(function(r) {
			var d = r.body.readAll();
			r.clear();
			r.response.body.write(d.toString().toUpperCase());
		}));

		s.asyncRun();

		var c = new net.Socket();
		c.connect('127.0.0.1', 9876);
		var r = new io.BufferedStream(c);

		r.writePacket(new Buffer('abcdefg'));
		var b = r.readPacket();
		assert.equal(b.toString(), 'ABCDEFG');

		r.writePacket(new Buffer('abcdefg'));
		var b = r.readPacket();
		assert.equal(b.toString(), 'ABCDEFG');
	});
Exemple #7
0
    it("charset", () => {
        fs.unlink(path.join(__dirname, "test0000" + base_port));

        f = fs.openFile(path.join(__dirname, "test0000" + base_port), "w+");
        var r = new io.BufferedStream(f);
        r.EOL = '\r\n';

        assert.equal(r.charset, "utf-8");

        f.write("哈哈哈\r\n");
        f.rewind();
        assert.equal(r.readLine(), "哈哈哈");

        r.charset = "gbk";

        f.rewind();
        f.truncate(0);
        r.writeText("嘿嘿嘿");
        r.writeLine("哈哈哈");
        f.rewind();
        assert.equal(f.readAll().toString("gbk"), "嘿嘿嘿哈哈哈\r\n");

        f.rewind();
        assert.equal(r.readText(6), "嘿嘿嘿");
        assert.equal(r.readLine(), "哈哈哈");

        f.close();
    });
Exemple #8
0
		function(v, f) {
			if (v.response.status !== 200) return;
			if (v.response.firstHeader("Content-Type").substring(0, 5) !== "text/") return;
			v.response.setHeader('Content-Type', 'application/x-javascript;charset=utf-8');

			if (application.router.static.amdCache === false) v.response.removeHeader("Last-Modified");
			var new_body = new io.MemoryStream();
			var repstream = new io.BufferedStream(new_body);

			if (f.indexOf("/tmpl/") > -1) {
				repstream.writeText('define("amd' + f.replace(/\//ig, ".") + '","');
				//console.debug(f, 'amd' + f.replace(/\//ig, "."))
			} else repstream.writeText('define("');

			if (v.response.length > 0) {
				var old_body = v.response.body;
				old_body.rewind();
				repstream.writeText(encoding.jsstr(old_body.readAll().toString()));
			}
			repstream.writeText('");');
			v.response.body.close();
			v.response.body = new_body;
		}
Exemple #9
0
 assert.throws(() => {
     r.readLine(9);
 });