Skip to content

Commit

Permalink
eslint (#314)
Browse files Browse the repository at this point in the history
* eslint

* only run on 18
  • Loading branch information
ZJONSSON authored May 11, 2024
1 parent a6e0392 commit 1149855
Show file tree
Hide file tree
Showing 45 changed files with 785 additions and 840 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ on:
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Linting with ESLint
uses: actions/setup-node@v3
with:
node-version: 18.x
- run: npm install
- run: npx eslint .

test:
runs-on: ubuntu-latest

Expand Down
29 changes: 29 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import globals from "globals";
import pluginJs from "@eslint/js";


export default [
{
rules:{
"semi": 2,
"no-multiple-empty-lines": 2,
"no-multi-spaces": 2,
"comma-spacing": 2,
"prefer-const": 2,
"no-trailing-spaces": 2,
"no-var": 2,
"indent": [
"error",
2,
{
"MemberExpression": 1,
"SwitchCase": 1,
"ignoredNodes": ["TemplateLiteral > *"]
}
],
}
},
{files: ["**/*.js"], languageOptions: {sourceType: "script"}},
{languageOptions: { globals: globals.node }},
pluginJs.configs.recommended,
];
19 changes: 9 additions & 10 deletions lib/BufferStream.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
var Promise = require('bluebird');
var Stream = require('stream');
const Stream = require('stream');

module.exports = function(entry) {
return new Promise(function(resolve,reject) {
var chunks = [];
var bufferStream = Stream.Transform()
.on('finish',function() {
return new Promise(function(resolve, reject) {
const chunks = [];
const bufferStream = Stream.Transform()
.on('finish', function() {
resolve(Buffer.concat(chunks));
})
.on('error',reject);
bufferStream._transform = function(d,e,cb) {
.on('error', reject);

bufferStream._transform = function(d, e, cb) {
chunks.push(d);
cb();
};
entry.on('error',reject)
entry.on('error', reject)
.pipe(bufferStream);
});
};
37 changes: 18 additions & 19 deletions lib/Decrypt.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
var bigInt = require('big-integer');
var Stream = require('stream');
const bigInt = require('big-integer');
const Stream = require('stream');

var table;
let table;

function generateTable() {
var poly = 0xEDB88320,c,n,k;
const poly = 0xEDB88320;
let c, n, k;
table = [];
for (n = 0; n < 256; n++) {
c = n;
for (k = 0; k < 8; k++)
c = (c & 1) ? poly ^ (c >>> 1) : c = c >>> 1;
c = (c & 1) ? poly ^ (c >>> 1) : c = c >>> 1;
table[n] = c >>> 0;
}
}

function crc(ch,crc) {
function crc(ch, crc) {
if (!table)
generateTable();

if (ch.charCodeAt)
ch = ch.charCodeAt(0);
ch = ch.charCodeAt(0);

return (bigInt(crc).shiftRight(8).and(0xffffff)).xor(table[bigInt(crc).xor(ch).and(0xff)]).value;
}
Expand All @@ -33,27 +34,27 @@ function Decrypt() {
this.key2 = 878082192;
}

Decrypt.prototype.update = function(h) {
this.key0 = crc(h,this.key0);
this.key1 = bigInt(this.key0).and(255).and(4294967295).add(this.key1)
Decrypt.prototype.update = function(h) {
this.key0 = crc(h, this.key0);
this.key1 = bigInt(this.key0).and(255).and(4294967295).add(this.key1);
this.key1 = bigInt(this.key1).multiply(134775813).add(1).and(4294967295).value;
this.key2 = crc(bigInt(this.key1).shiftRight(24).and(255), this.key2);
}
};


Decrypt.prototype.decryptByte = function(c) {
var k = bigInt(this.key2).or(2);
const k = bigInt(this.key2).or(2);
c = c ^ bigInt(k).multiply(bigInt(k^1)).shiftRight(8).and(255);
this.update(c);
return c;
};

Decrypt.prototype.stream = function() {
var stream = Stream.Transform(),
self = this;
Decrypt.prototype.stream = function() {
const stream = Stream.Transform(),
self = this;

stream._transform = function(d,e,cb) {
for (var i = 0; i<d.length;i++) {
stream._transform = function(d, e, cb) {
for (let i = 0; i<d.length;i++) {
d[i] = self.decryptByte(d[i]);
}
this.push(d);
Expand All @@ -63,6 +64,4 @@ Decrypt.prototype.decryptByte = function(c) {
};




module.exports = Decrypt;
10 changes: 5 additions & 5 deletions lib/NoopStream.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
var Stream = require('stream');
var util = require('util');
const Stream = require('stream');
const util = require('util');
function NoopStream() {
if (!(this instanceof NoopStream)) {
return new NoopStream();
}
Stream.Transform.call(this);
}

util.inherits(NoopStream,Stream.Transform);
util.inherits(NoopStream, Stream.Transform);

NoopStream.prototype._transform = function(d, e, cb) { cb() ;};

NoopStream.prototype._transform = function(d,e,cb) { cb() ;};

module.exports = NoopStream;
Loading

0 comments on commit 1149855

Please sign in to comment.