steamutils 1.5.5 → 1.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utils.js +34 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.5.05",
3
+ "version": "1.5.06",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "alpha-common-utils": "^1.0.6",
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
+ }