steamutils 1.5.6 → 1.5.7
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/utils.js +27 -0
package/package.json
CHANGED
package/utils.js
CHANGED
@@ -4,6 +4,9 @@ import { EAuthTokenPlatformType } from "./const.js";
|
|
4
4
|
import fs from "fs";
|
5
5
|
import axios from "axios";
|
6
6
|
import readline from "readline";
|
7
|
+
import https from "https";
|
8
|
+
import { promisify } from "util";
|
9
|
+
import { pipeline } from "stream";
|
7
10
|
|
8
11
|
const isBrowser = typeof window !== "undefined";
|
9
12
|
const g_rgCurrencyData = {
|
@@ -1050,6 +1053,30 @@ export async function downloadImage(url, filePath) {
|
|
1050
1053
|
});
|
1051
1054
|
}
|
1052
1055
|
|
1056
|
+
export async function downloadLargeImage(url, filePath) {
|
1057
|
+
try {
|
1058
|
+
const response = await new Promise((resolve, reject) => {
|
1059
|
+
https
|
1060
|
+
.get(url, (res) => {
|
1061
|
+
if (res.statusCode === 200) {
|
1062
|
+
resolve(res);
|
1063
|
+
} else {
|
1064
|
+
reject(new Error(`Failed to get image, status code: ${res.statusCode}`));
|
1065
|
+
}
|
1066
|
+
})
|
1067
|
+
.on("error", reject);
|
1068
|
+
});
|
1069
|
+
|
1070
|
+
const streamPipeline = promisify(pipeline);
|
1071
|
+
await streamPipeline(response, fs.createWriteStream(filePath));
|
1072
|
+
console.log("Download large image completed.");
|
1073
|
+
return true;
|
1074
|
+
} catch (error) {
|
1075
|
+
console.error(`Error downloading large image: ${error.message}`);
|
1076
|
+
return false;
|
1077
|
+
}
|
1078
|
+
}
|
1079
|
+
|
1053
1080
|
//from large text file
|
1054
1081
|
export function readRandomLine(filePath) {
|
1055
1082
|
return new Promise((resolve, reject) => {
|