first commit

This commit is contained in:
2026-09-08 20:28:54 +08:00
commit 2ada8d3d5a
37380 changed files with 4886169 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
(function() {
var Logcat, Priority, Reader;
Reader = require('./logcat/reader');
Priority = require('./logcat/priority');
Logcat = (function() {
function Logcat() {}
Logcat.readStream = function(stream, options) {
return new Reader(options).connect(stream);
};
return Logcat;
})();
Logcat.Reader = Reader;
Logcat.Priority = Priority;
module.exports = Logcat;
}).call(this);
+76
View File
@@ -0,0 +1,76 @@
(function() {
var Entry;
Entry = (function() {
function Entry() {
this.date = null;
this.pid = -1;
this.tid = -1;
this.priority = null;
this.tag = null;
this.message = null;
}
Entry.prototype.setDate = function(date) {
this.date = date;
};
Entry.prototype.setPid = function(pid) {
this.pid = pid;
};
Entry.prototype.setTid = function(tid) {
this.tid = tid;
};
Entry.prototype.setPriority = function(priority) {
this.priority = priority;
};
Entry.prototype.setTag = function(tag) {
this.tag = tag;
};
Entry.prototype.setMessage = function(message) {
this.message = message;
};
Entry.prototype.toBinary = function() {
var buffer, cursor, length;
length = 20;
length += 1;
length += this.tag.length;
length += 1;
length += this.message.length;
length += 1;
buffer = new Buffer(length);
cursor = 0;
buffer.writeUInt16LE(length - 20, cursor);
cursor += 4;
buffer.writeInt32LE(this.pid, cursor);
cursor += 4;
buffer.writeInt32LE(this.tid, cursor);
cursor += 4;
buffer.writeInt32LE(Math.floor(this.date.getTime() / 1000), cursor);
cursor += 4;
buffer.writeInt32LE((this.date.getTime() % 1000) * 1000000, cursor);
cursor += 4;
buffer[cursor] = this.priority;
cursor += 1;
buffer.write(this.tag, cursor, this.tag.length);
cursor += this.tag.length;
buffer[cursor] = 0x00;
cursor += 1;
buffer.write(this.message, cursor, this.message.length);
cursor += this.message.length;
buffer[cursor] = 0x00;
return buffer;
};
return Entry;
})();
module.exports = Entry;
}).call(this);
+31
View File
@@ -0,0 +1,31 @@
(function() {
var EventEmitter, Parser,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
EventEmitter = require('events').EventEmitter;
Parser = (function(superClass) {
extend(Parser, superClass);
function Parser() {
return Parser.__super__.constructor.apply(this, arguments);
}
Parser.get = function(type) {
var parser;
parser = require("./parser/" + type);
return new parser();
};
Parser.prototype.parse = function() {
throw new Error("parse() is unimplemented");
};
return Parser;
})(EventEmitter);
module.exports = Parser;
}).call(this);
+86
View File
@@ -0,0 +1,86 @@
(function() {
var Binary, Entry, Parser, Priority,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Parser = require('../parser');
Entry = require('../entry');
Priority = require('../priority');
Binary = (function(superClass) {
var HEADER_SIZE_MAX, HEADER_SIZE_V1;
extend(Binary, superClass);
HEADER_SIZE_V1 = 20;
HEADER_SIZE_MAX = 100;
function Binary() {
this.buffer = new Buffer('');
}
Binary.prototype.parse = function(chunk) {
var cursor, data, entry, headerSize, length, nsec, sec;
this.buffer = Buffer.concat([this.buffer, chunk]);
while (this.buffer.length > 4) {
cursor = 0;
length = this.buffer.readUInt16LE(cursor);
cursor += 2;
headerSize = this.buffer.readUInt16LE(cursor);
if (headerSize < HEADER_SIZE_V1 || headerSize > HEADER_SIZE_MAX) {
headerSize = HEADER_SIZE_V1;
}
cursor += 2;
if (this.buffer.length < headerSize + length) {
break;
}
entry = new Entry;
entry.setPid(this.buffer.readInt32LE(cursor));
cursor += 4;
entry.setTid(this.buffer.readInt32LE(cursor));
cursor += 4;
sec = this.buffer.readInt32LE(cursor);
cursor += 4;
nsec = this.buffer.readInt32LE(cursor);
entry.setDate(new Date(sec * 1000 + nsec / 1000000));
cursor += 4;
cursor = headerSize;
data = this.buffer.slice(cursor, cursor + length);
cursor += length;
this.buffer = this.buffer.slice(cursor);
this._processEntry(entry, data);
}
if (this.buffer.length) {
this.emit('wait');
} else {
this.emit('drain');
}
};
Binary.prototype._processEntry = function(entry, data) {
var cursor, length;
entry.setPriority(data[0]);
cursor = 1;
length = data.length;
while (cursor < length) {
if (data[cursor] === 0) {
entry.setTag(data.slice(1, cursor).toString());
entry.setMessage(data.slice(cursor + 1, length - 1).toString());
this.emit('entry', entry);
return;
}
cursor += 1;
}
this.emit('error', new Error("Unprocessable entry data '" + data + "'"));
};
return Binary;
})(Parser);
module.exports = Binary;
}).call(this);
+89
View File
@@ -0,0 +1,89 @@
(function() {
var Priority;
Priority = (function() {
var letterNames, letters, names;
function Priority() {}
Priority.UNKNOWN = 0;
Priority.DEFAULT = 1;
Priority.VERBOSE = 2;
Priority.DEBUG = 3;
Priority.INFO = 4;
Priority.WARN = 5;
Priority.ERROR = 6;
Priority.FATAL = 7;
Priority.SILENT = 8;
names = {
0: 'UNKNOWN',
1: 'DEFAULT',
2: 'VERBOSE',
3: 'DEBUG',
4: 'INFO',
5: 'WARN',
6: 'ERROR',
7: 'FATAL',
8: 'SILENT'
};
letters = {
'?': Priority.UNKNOWN,
'V': Priority.VERBOSE,
'D': Priority.DEBUG,
'I': Priority.INFO,
'W': Priority.WARN,
'E': Priority.ERROR,
'F': Priority.FATAL,
'S': Priority.SILENT
};
letterNames = {
0: '?',
1: '?',
2: 'V',
3: 'D',
4: 'I',
5: 'W',
6: 'E',
7: 'F',
8: 'S'
};
Priority.fromName = function(name) {
var value;
value = Priority[name.toUpperCase()];
if (value || value === 0) {
return value;
}
return Priority.fromLetter(name);
};
Priority.toName = function(value) {
return names[value];
};
Priority.fromLetter = function(letter) {
return letters[letter.toUpperCase()];
};
Priority.toLetter = function(value) {
return letterNames[value];
};
return Priority;
})();
module.exports = Priority;
}).call(this);
+150
View File
@@ -0,0 +1,150 @@
(function() {
var EventEmitter, Parser, Priority, Reader, Transform,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
EventEmitter = require('events').EventEmitter;
Parser = require('./parser');
Transform = require('./transform');
Priority = require('./priority');
Reader = (function(superClass) {
extend(Reader, superClass);
Reader.ANY = '*';
function Reader(options) {
var base;
this.options = options != null ? options : {};
(base = this.options).format || (base.format = 'binary');
if (this.options.fixLineFeeds == null) {
this.options.fixLineFeeds = true;
}
this.filters = {
all: -1,
tags: {}
};
this.parser = Parser.get(this.options.format);
this.stream = null;
}
Reader.prototype.exclude = function(tag) {
if (tag === Reader.ANY) {
return this.excludeAll();
}
this.filters.tags[tag] = Priority.SILENT;
return this;
};
Reader.prototype.excludeAll = function() {
this.filters.all = Priority.SILENT;
return this;
};
Reader.prototype.include = function(tag, priority) {
if (priority == null) {
priority = Priority.DEBUG;
}
if (tag === Reader.ANY) {
return this.includeAll(priority);
}
this.filters.tags[tag] = this._priority(priority);
return this;
};
Reader.prototype.includeAll = function(priority) {
if (priority == null) {
priority = Priority.DEBUG;
}
this.filters.all = this._priority(priority);
return this;
};
Reader.prototype.resetFilters = function() {
this.filters.all = -1;
this.filters.tags = {};
return this;
};
Reader.prototype._hook = function() {
var transform;
if (this.options.fixLineFeeds) {
transform = this.stream.pipe(new Transform);
transform.on('data', (function(_this) {
return function(data) {
return _this.parser.parse(data);
};
})(this));
} else {
this.stream.on('data', (function(_this) {
return function(data) {
return _this.parser.parse(data);
};
})(this));
}
this.stream.on('error', (function(_this) {
return function(err) {
return _this.emit('error', err);
};
})(this));
this.stream.on('end', (function(_this) {
return function() {
return _this.emit('end');
};
})(this));
this.stream.on('finish', (function(_this) {
return function() {
return _this.emit('finish');
};
})(this));
this.parser.on('entry', (function(_this) {
return function(entry) {
if (_this._filter(entry)) {
return _this.emit('entry', entry);
}
};
})(this));
this.parser.on('error', (function(_this) {
return function(err) {
return _this.emit('error', err);
};
})(this));
};
Reader.prototype._filter = function(entry) {
var priority;
priority = this.filters.tags[entry.tag];
if (!(priority >= 0)) {
priority = this.filters.all;
}
return entry.priority >= priority;
};
Reader.prototype._priority = function(priority) {
if (typeof priority === 'number') {
return priority;
}
return Priority.fromName(priority);
};
Reader.prototype.connect = function(stream) {
this.stream = stream;
this._hook();
return this;
};
Reader.prototype.end = function() {
this.stream.end();
return this;
};
return Reader;
})(EventEmitter);
module.exports = Reader;
}).call(this);
+51
View File
@@ -0,0 +1,51 @@
(function() {
var Stream, Transform,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Stream = require('stream');
Transform = (function(superClass) {
extend(Transform, superClass);
function Transform(options) {
this.savedR = null;
Transform.__super__.constructor.call(this, options);
}
Transform.prototype._transform = function(chunk, encoding, done) {
var hi, last, lo;
lo = 0;
hi = 0;
if (this.savedR) {
if (chunk[0] !== 0x0a) {
this.push(this.savedR);
}
this.savedR = null;
}
last = chunk.length - 1;
while (hi <= last) {
if (chunk[hi] === 0x0d) {
if (hi === last) {
this.savedR = chunk.slice(last);
break;
} else if (chunk[hi + 1] === 0x0a) {
this.push(chunk.slice(lo, hi));
lo = hi + 1;
}
}
hi += 1;
}
if (hi !== lo) {
this.push(chunk.slice(lo, hi));
}
done();
};
return Transform;
})(Stream.Transform);
module.exports = Transform;
}).call(this);