starling-framework
Version:
A fast, productive library for 2D cross-platform development.
240 lines (222 loc) • 6 kB
JavaScript
// Class: haxe.io.Input
var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this
$global.Object.defineProperty(exports, "__esModule", {value: true});
var __map_reserved = {};
// Imports
var $hxClasses = require("./../../hxClasses_stub").default;
var $hxEnums = require("./../../hxEnums_stub").default;
var $import = require("./../../import_stub").default;
function js__$Boot_HaxeError() {return require("./../../js/_Boot/HaxeError");}
function haxe_io_Error() {return require("./../../haxe/io/Error");}
function haxe_io_Eof() {return require("./../../haxe/io/Eof");}
function haxe_io_Bytes() {return require("./../../haxe/io/Bytes");}
function haxe_io_BytesBuffer() {return require("./../../haxe/io/BytesBuffer");}
function HxOverrides() {return require("./../../HxOverrides");}
function haxe_io_FPHelper() {return require("./../../haxe/io/FPHelper");}
// Constructor
var Input = function(){}
// Meta
Input.__name__ = "haxe.io.Input";
Input.__isInterface__ = false;
Input.prototype = {
readByte: function() {
throw new (js__$Boot_HaxeError().default)("Not implemented");
},
readBytes: function(s,pos,len) {
var k = len;
var b = s.b;
if(pos < 0 || len < 0 || pos + len > s.length) {
throw new (js__$Boot_HaxeError().default)((haxe_io_Error().default).OutsideBounds);
}
try {
while(k > 0) {
b[pos] = this.readByte();
++pos;
--k;
}
} catch( eof ) {
var eof1 = ((eof) instanceof (js__$Boot_HaxeError().default)) ? eof.val : eof;
if(((eof1) instanceof (haxe_io_Eof().default))) {
var eof2 = eof1;
} else {
throw eof;
}
}
return len - k;
},
close: function() {
},
set_bigEndian: function(b) {
this.bigEndian = b;
return b;
},
readAll: function(bufsize) {
if(bufsize == null) {
bufsize = 16384;
}
var buf = (haxe_io_Bytes().default).alloc(bufsize);
var total = new (haxe_io_BytesBuffer().default)();
try {
while(true) {
var len = this.readBytes(buf,0,bufsize);
if(len == 0) {
throw new (js__$Boot_HaxeError().default)((haxe_io_Error().default).Blocked);
}
total.addBytes(buf,0,len);
}
} catch( e ) {
var e1 = ((e) instanceof (js__$Boot_HaxeError().default)) ? e.val : e;
if(((e1) instanceof (haxe_io_Eof().default))) {
var e2 = e1;
} else {
throw e;
}
}
return total.getBytes();
},
readFullBytes: function(s,pos,len) {
while(len > 0) {
var k = this.readBytes(s,pos,len);
if(k == 0) {
throw new (js__$Boot_HaxeError().default)((haxe_io_Error().default).Blocked);
}
pos += k;
len -= k;
}
},
read: function(nbytes) {
var s = (haxe_io_Bytes().default).alloc(nbytes);
var p = 0;
while(nbytes > 0) {
var k = this.readBytes(s,p,nbytes);
if(k == 0) {
throw new (js__$Boot_HaxeError().default)((haxe_io_Error().default).Blocked);
}
p += k;
nbytes -= k;
}
return s;
},
readUntil: function(end) {
var buf = new (haxe_io_BytesBuffer().default)();
var last;
while(true) {
last = this.readByte();
if(!(last != end)) {
break;
}
buf.addByte(last);
}
return buf.getBytes().toString();
},
readLine: function() {
var buf = new (haxe_io_BytesBuffer().default)();
var last;
var s;
try {
while(true) {
last = this.readByte();
if(!(last != 10)) {
break;
}
buf.addByte(last);
}
s = buf.getBytes().toString();
if((HxOverrides().default).cca(s,s.length - 1) == 13) {
s = (HxOverrides().default).substr(s,0,-1);
}
} catch( e ) {
var e1 = ((e) instanceof (js__$Boot_HaxeError().default)) ? e.val : e;
if(((e1) instanceof (haxe_io_Eof().default))) {
s = buf.getBytes().toString();
if(s.length == 0) {
throw new (js__$Boot_HaxeError().default)(e1);
}
} else {
throw e;
}
}
return s;
},
readFloat: function() {
return (haxe_io_FPHelper().default).i32ToFloat(this.readInt32());
},
readDouble: function() {
var i1 = this.readInt32();
var i2 = this.readInt32();
if(this.bigEndian) {
return (haxe_io_FPHelper().default).i64ToDouble(i2,i1);
} else {
return (haxe_io_FPHelper().default).i64ToDouble(i1,i2);
}
},
readInt8: function() {
var n = this.readByte();
if(n >= 128) {
return n - 256;
}
return n;
},
readInt16: function() {
var ch1 = this.readByte();
var ch2 = this.readByte();
var n = this.bigEndian ? ch2 | ch1 << 8 : ch1 | ch2 << 8;
if((n & 32768) != 0) {
return n - 65536;
}
return n;
},
readUInt16: function() {
var ch1 = this.readByte();
var ch2 = this.readByte();
if(this.bigEndian) {
return ch2 | ch1 << 8;
} else {
return ch1 | ch2 << 8;
}
},
readInt24: function() {
var ch1 = this.readByte();
var ch2 = this.readByte();
var ch3 = this.readByte();
var n = this.bigEndian ? ch3 | ch2 << 8 | ch1 << 16 : ch1 | ch2 << 8 | ch3 << 16;
if((n & 8388608) != 0) {
return n - 16777216;
}
return n;
},
readUInt24: function() {
var ch1 = this.readByte();
var ch2 = this.readByte();
var ch3 = this.readByte();
if(this.bigEndian) {
return ch3 | ch2 << 8 | ch1 << 16;
} else {
return ch1 | ch2 << 8 | ch3 << 16;
}
},
readInt32: function() {
var ch1 = this.readByte();
var ch2 = this.readByte();
var ch3 = this.readByte();
var ch4 = this.readByte();
if(this.bigEndian) {
return ch4 | ch3 << 8 | ch2 << 16 | ch1 << 24;
} else {
return ch1 | ch2 << 8 | ch3 << 16 | ch4 << 24;
}
},
readString: function(len,encoding) {
var b = (haxe_io_Bytes().default).alloc(len);
this.readFullBytes(b,0,len);
return b.getString(0,len,encoding);
},
getDoubleSig: function(bytes) {
return ((bytes[1] & 15) << 16 | bytes[2] << 8 | bytes[3]) * 4294967296. + (bytes[4] >> 7) * 2147483648 + ((bytes[4] & 127) << 24 | bytes[5] << 16 | bytes[6] << 8 | bytes[7]);
}
};
Input.prototype.__class__ = Input.prototype.constructor = $hxClasses["haxe.io.Input"] = Input;
// Init
// Statics
// Export
exports.default = Input;