node-nim 10.9.70 → 10.9.71-beta.69

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.70",
3
+ "version": "10.9.71-beta.69",
4
4
  "description": "NetEase IM nodejs wrapper based on NetEase IM C++ SDK",
5
5
  "main": "dist/node-nim.js",
6
6
  "bin": {
@@ -33,10 +33,11 @@
33
33
  ]
34
34
  },
35
35
  "dependencies": {
36
- "compare-versions": "^4.1.4",
37
- "download": "^8.0.0",
38
36
  "eventemitter3": "^4.0.7",
39
- "node-fetch": "^2.6.9"
37
+ "compare-versions": "^4.1.4",
38
+ "node-fetch": "^2.6.9",
39
+ "yauzl": "^2.10.0",
40
+ "tar": "^6.2.0"
40
41
  },
41
42
  "devDependencies": {
42
43
  "@babel/preset-env": "^7.24.0",
@@ -2,7 +2,11 @@ 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 download = require('download')
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)
6
10
 
7
11
  // Global variables
8
12
  const default_arch = 'universal'
@@ -25,6 +29,117 @@ if (process.env.npm_package_version) {
25
29
  if (process.env.npm_config_nimsdkversion) {
26
30
  version = process.env.npm_config_nimsdkversion
27
31
  }
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
+ }
28
143
  async function downloadSDK(custom_sdk_url) {
29
144
  if (custom_sdk_url) {
30
145
  downloadUrl = custom_sdk_url
@@ -74,12 +189,8 @@ async function downloadSDK(custom_sdk_url) {
74
189
  }
75
190
  // download sdk
76
191
  try {
77
- await download(downloadUrl, savePath, {
78
- extract: true,
79
- filter: (file) => {
80
- return !file.path.includes('._')
81
- }
82
- })
192
+ await downloadAndExtract(downloadUrl, savePath)
193
+
83
194
  // create build/Release folder
84
195
  if (!fs.existsSync(target)) {
85
196
  fs.mkdirSync(target, { recursive: true })