node-nim 10.9.71-beta.69 → 10.9.71

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-nim",
3
- "version": "10.9.71-beta.69",
3
+ "version": "10.9.71",
4
4
  "description": "NetEase IM nodejs wrapper based on NetEase IM C++ SDK",
5
5
  "main": "dist/node-nim.js",
6
6
  "bin": {
@@ -33,11 +33,10 @@
33
33
  ]
34
34
  },
35
35
  "dependencies": {
36
- "eventemitter3": "^4.0.7",
37
36
  "compare-versions": "^4.1.4",
38
- "node-fetch": "^2.6.9",
39
- "yauzl": "^2.10.0",
40
- "tar": "^6.2.0"
37
+ "download": "^8.0.0",
38
+ "eventemitter3": "^4.0.7",
39
+ "node-fetch": "^2.6.9"
41
40
  },
42
41
  "devDependencies": {
43
42
  "@babel/preset-env": "^7.24.0",
@@ -2,11 +2,7 @@ const fetch = require('node-fetch')
2
2
  const fs = require('fs')
3
3
  const path = require('path')
4
4
  const compareVersions = require('compare-versions')
5
- const yauzl = require('yauzl')
6
- const tar = require('tar')
7
- const { pipeline } = require('stream')
8
- const { promisify } = require('util')
9
- const pipelineAsync = promisify(pipeline)
5
+ const download = require('download')
10
6
 
11
7
  // Global variables
12
8
  const default_arch = 'universal'
@@ -29,117 +25,6 @@ if (process.env.npm_package_version) {
29
25
  if (process.env.npm_config_nimsdkversion) {
30
26
  version = process.env.npm_config_nimsdkversion
31
27
  }
32
-
33
- // Download and extract function to replace the 'download' package
34
- async function downloadAndExtract(url, destination) {
35
- if (!fs.existsSync(destination)) {
36
- fs.mkdirSync(destination, { recursive: true })
37
- }
38
-
39
- // Download the file
40
- const response = await fetch(url)
41
- if (!response.ok) {
42
- throw new Error(`Failed to download: ${response.statusText}`)
43
- }
44
-
45
- // Determine file type from URL
46
- const isZip = url.toLowerCase().includes('.zip')
47
- const isTarGz = url.toLowerCase().includes('.tar.gz') || url.toLowerCase().includes('.tgz')
48
-
49
- let archivePath
50
- let fileExtension
51
-
52
- if (isZip) {
53
- fileExtension = '.zip'
54
- archivePath = path.join(destination, 'temp.zip')
55
- } else if (isTarGz) {
56
- fileExtension = '.tar.gz'
57
- archivePath = path.join(destination, 'temp.tar.gz')
58
- } else {
59
- // Default to zip if we can't determine the type
60
- fileExtension = '.zip'
61
- archivePath = path.join(destination, 'temp.zip')
62
- console.warn('[node-nim] Could not determine archive type from URL, assuming ZIP format')
63
- }
64
-
65
- // Save the downloaded file
66
- const writeStream = fs.createWriteStream(archivePath)
67
- await pipelineAsync(response.body, writeStream)
68
-
69
- // Extract based on file type
70
- if (isTarGz) {
71
- await extractTarGz(archivePath, destination)
72
- } else {
73
- await extractZip(archivePath, destination)
74
- }
75
-
76
- // Clean up the temporary archive file
77
- fs.unlinkSync(archivePath)
78
- }
79
-
80
- // Extract ZIP files
81
- async function extractZip(zipPath, destination) {
82
- return new Promise((resolve, reject) => {
83
- yauzl.open(zipPath, { lazyEntries: true }, (err, zipfile) => {
84
- if (err) return reject(err)
85
-
86
- zipfile.readEntry()
87
- zipfile.on('entry', (entry) => {
88
- // Filter out macOS hidden files (._files)
89
- if (entry.fileName.includes('._')) {
90
- zipfile.readEntry()
91
- return
92
- }
93
-
94
- if (/\/$/.test(entry.fileName)) {
95
- // Directory entry
96
- const dirPath = path.join(destination, entry.fileName)
97
- fs.mkdirSync(dirPath, { recursive: true })
98
- zipfile.readEntry()
99
- } else {
100
- // File entry
101
- zipfile.openReadStream(entry, (err, readStream) => {
102
- if (err) return reject(err)
103
-
104
- const filePath = path.join(destination, entry.fileName)
105
- const fileDir = path.dirname(filePath)
106
-
107
- if (!fs.existsSync(fileDir)) {
108
- fs.mkdirSync(fileDir, { recursive: true })
109
- }
110
-
111
- const writeStream = fs.createWriteStream(filePath)
112
- readStream.pipe(writeStream)
113
-
114
- writeStream.on('close', () => {
115
- zipfile.readEntry()
116
- })
117
-
118
- writeStream.on('error', reject)
119
- })
120
- }
121
- })
122
-
123
- zipfile.on('end', () => {
124
- resolve()
125
- })
126
-
127
- zipfile.on('error', reject)
128
- })
129
- })
130
- }
131
-
132
- // Extract TAR.GZ files
133
- async function extractTarGz(tarPath, destination) {
134
- return tar.extract({
135
- file: tarPath,
136
- cwd: destination,
137
- filter: (path, entry) => {
138
- // Filter out macOS hidden files (._files)
139
- return !path.includes('/._') && !path.startsWith('._')
140
- }
141
- })
142
- }
143
28
  async function downloadSDK(custom_sdk_url) {
144
29
  if (custom_sdk_url) {
145
30
  downloadUrl = custom_sdk_url
@@ -189,8 +74,12 @@ async function downloadSDK(custom_sdk_url) {
189
74
  }
190
75
  // download sdk
191
76
  try {
192
- await downloadAndExtract(downloadUrl, savePath)
193
-
77
+ await download(downloadUrl, savePath, {
78
+ extract: true,
79
+ filter: (file) => {
80
+ return !file.path.includes('._')
81
+ }
82
+ })
194
83
  // create build/Release folder
195
84
  if (!fs.existsSync(target)) {
196
85
  fs.mkdirSync(target, { recursive: true })