steamutils 1.5.5 → 1.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/utils.js +34 -0
package/package.json
CHANGED
package/utils.js
CHANGED
@@ -3,6 +3,7 @@ import SteamTotp from "steam-totp";
|
|
3
3
|
import { EAuthTokenPlatformType } from "./const.js";
|
4
4
|
import fs from "fs";
|
5
5
|
import axios from "axios";
|
6
|
+
import readline from "readline";
|
6
7
|
|
7
8
|
const isBrowser = typeof window !== "undefined";
|
8
9
|
const g_rgCurrencyData = {
|
@@ -1048,3 +1049,36 @@ export async function downloadImage(url, filePath) {
|
|
1048
1049
|
});
|
1049
1050
|
});
|
1050
1051
|
}
|
1052
|
+
|
1053
|
+
//from large text file
|
1054
|
+
export function readRandomLine(filePath) {
|
1055
|
+
return new Promise((resolve, reject) => {
|
1056
|
+
const rl = readline.createInterface({
|
1057
|
+
input: fs.createReadStream(filePath),
|
1058
|
+
crlfDelay: Infinity,
|
1059
|
+
});
|
1060
|
+
|
1061
|
+
let resultLine = null;
|
1062
|
+
let lineNumber = 0;
|
1063
|
+
|
1064
|
+
rl.on("line", (line) => {
|
1065
|
+
lineNumber += 1;
|
1066
|
+
// Choose this line with probability 1 / lineNumber
|
1067
|
+
if (Math.random() < 1 / lineNumber) {
|
1068
|
+
resultLine = line;
|
1069
|
+
}
|
1070
|
+
});
|
1071
|
+
|
1072
|
+
rl.on("close", () => {
|
1073
|
+
if (resultLine !== null) {
|
1074
|
+
resolve(resultLine);
|
1075
|
+
} else {
|
1076
|
+
reject(new Error("File is empty"));
|
1077
|
+
}
|
1078
|
+
});
|
1079
|
+
|
1080
|
+
rl.on("error", (err) => {
|
1081
|
+
reject(err);
|
1082
|
+
});
|
1083
|
+
});
|
1084
|
+
}
|