69 lines
2.6 KiB
JavaScript
69 lines
2.6 KiB
JavaScript
|
|
// Generated by CoffeeScript 1.7.1
|
||
|
|
(function() {
|
||
|
|
({
|
||
|
|
parseUrl: function(url) {
|
||
|
|
var content, req;
|
||
|
|
req = new XMLHttpRequest();
|
||
|
|
req.open('GET', url, false);
|
||
|
|
req.overrideMimeType('text/plain; charset=x-user-defined');
|
||
|
|
req.send(null);
|
||
|
|
content = req.status === 200 || req.status === 0 ? req.responseText : '';
|
||
|
|
return this.parse(content);
|
||
|
|
},
|
||
|
|
parse: function(content) {
|
||
|
|
var commentMarker, i, sauceMarker;
|
||
|
|
sauceMarker = content.length - 128;
|
||
|
|
if (content.substr(sauceMarker, 5) !== 'SAUCE') {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
this.id = 'SAUCE';
|
||
|
|
this.version = content.substr(sauceMarker + 5, 2);
|
||
|
|
this.title = content.substr(sauceMarker + 7, 35);
|
||
|
|
this.author = content.substr(sauceMarker + 42, 20);
|
||
|
|
this.group = content.substr(sauceMarker + 62, 20);
|
||
|
|
this.date = content.substr(sauceMarker + 82, 8);
|
||
|
|
this.fileSize = this.unpackLong(content.substr(sauceMarker + 90, 4));
|
||
|
|
this.dataType = this.getByteAt(content.substr(sauceMarker + 94, 1));
|
||
|
|
this.fileType = this.getByteAt(content.substr(sauceMarker + 95, 1));
|
||
|
|
this.tinfo1 = this.unpackShort(content.substr(sauceMarker + 96, 2));
|
||
|
|
this.tinfo2 = this.unpackShort(content.substr(sauceMarker + 98, 2));
|
||
|
|
this.tinfo3 = this.unpackShort(content.substr(sauceMarker + 100, 2));
|
||
|
|
this.tinfo4 = this.unpackShort(content.substr(sauceMarker + 102, 2));
|
||
|
|
this.commentCount = this.getByteAt(content.substr(sauceMarker + 104, 1));
|
||
|
|
this.flags = this.getByteAt(content.substr(sauceMarker + 105, 1));
|
||
|
|
this.filler = content.substr(sauceMarker + 106, 22);
|
||
|
|
commentMarker = sauceMarker - 5 - this.commentCount * 64;
|
||
|
|
if (this.commentCount > 0 && content.substr(commentMarker, 5) === 'COMNT') {
|
||
|
|
commentMarker += 5;
|
||
|
|
this.comments = [];
|
||
|
|
i = this.commentCount;
|
||
|
|
while (i-- > 0) {
|
||
|
|
this.comments.push(content.substr(commentMarker, 64));
|
||
|
|
commentMarker += 64;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
},
|
||
|
|
unpackLong: function(data) {
|
||
|
|
var lng;
|
||
|
|
lng = (((this.getByteAt(data, 3) << 8) + this.getByteAt(data, 2) << 8) + this.getByteAt(data, 1) << 8) + this.getByteAt(data, 0);
|
||
|
|
if (lng < 0) {
|
||
|
|
lng += 4294967296;
|
||
|
|
}
|
||
|
|
return lng;
|
||
|
|
},
|
||
|
|
unpackShort: function(data) {
|
||
|
|
var shrt;
|
||
|
|
shrt = (this.getByteAt(data, 1) << 8) + this.getByteAt(data, 0);
|
||
|
|
if (shrt < 0) {
|
||
|
|
shrt += 65536;
|
||
|
|
}
|
||
|
|
return shrt;
|
||
|
|
},
|
||
|
|
getByteAt: function(data, offset) {
|
||
|
|
return data.charCodeAt(offset) & 0xFF;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
}).call(this);
|