steamutils 1.5.6 → 1.5.7

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utils.js +27 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.5.06",
3
+ "version": "1.5.07",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "alpha-common-utils": "^1.0.6",
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) => {