Create hartool.js

This commit is contained in:
Namhyeon Go 2024-08-03 15:25:41 +09:00 committed by GitHub
parent f55b70585a
commit 45a1938aea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

44
lib/hartool.js Normal file
View File

@ -0,0 +1,44 @@
// hartool.js
// https://github.com/gnh1201/welsonjs
var PipeIPC = require("lib/pipe-ipc");
var HARObject = function() {
this.filename = null;
this.data = null;
this.entryIndex = 0;
this.setEntryIndex = function(index) {
this.entryIndex = index;
};
this.load = function(filename) {
this.filename = filename;
this.data = JSON.parse(FILE.readFile(filename, PipeIPC.CdoUTF_8));
return this;
};
this.walk = function(onEntry) {
if (this.data = null)
return;
var entries = this.data.entries;
while (this.entryIndex < entries.length) {
var entry = this.data.entries[entryIndex];
try {
onEntry(this, entry, entry.request, entry.response);
} catch (e) {
console.error(e.message);
}
this.entryIndex++;
}
};
};
exports.HARObject = HARObject;
exports.VERSIONINFO = "HAR tool version 0.1";
exports.AUTHOR = "abuse@catswords.net";
exports.global = global;
exports.require = require;