@oxiaom/adoremix 1.0.65 → 1.0.66
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 +1 -1
- package/src/mp3server-server.js +15 -2
package/package.json
CHANGED
package/src/mp3server-server.js
CHANGED
|
@@ -92,6 +92,8 @@ function startServer(opts) {
|
|
|
92
92
|
let fd = null;
|
|
93
93
|
let audioStart = 0;
|
|
94
94
|
let fileSize = 0;
|
|
95
|
+
let totalSize = 0;
|
|
96
|
+
let offset = 0;
|
|
95
97
|
let filePath = '';
|
|
96
98
|
let state = 'path'; // path → chunks
|
|
97
99
|
let pending = Buffer.alloc(0);
|
|
@@ -128,7 +130,9 @@ function startServer(opts) {
|
|
|
128
130
|
return fail('Invalid MP3 file format');
|
|
129
131
|
}
|
|
130
132
|
filePath = line;
|
|
133
|
+
totalSize = st.size;
|
|
131
134
|
fileSize = st.size - audioStart;
|
|
135
|
+
offset = audioStart;
|
|
132
136
|
state = 'chunks';
|
|
133
137
|
log(`[info] ${peer} 推送 ${line} 起始=${audioStart} 大小=${fileSize}`);
|
|
134
138
|
sock.write(String(fileSize) + '\n');
|
|
@@ -147,7 +151,7 @@ function startServer(opts) {
|
|
|
147
151
|
|
|
148
152
|
const buf = Buffer.alloc(n);
|
|
149
153
|
let got;
|
|
150
|
-
try { got = fs.readSync(fd, buf, 0, n,
|
|
154
|
+
try { got = fs.readSync(fd, buf, 0, n, offset); } catch (e) { return fail('File read error'); }
|
|
151
155
|
if (got === 0) {
|
|
152
156
|
// 到文件尾:回 close 并断开(与 C++ 一致)
|
|
153
157
|
try { sock.write('close\n', () => sock.end()); } catch (e) {}
|
|
@@ -155,8 +159,17 @@ function startServer(opts) {
|
|
|
155
159
|
log(`[info] ${peer} 完成 ${filePath}`);
|
|
156
160
|
return;
|
|
157
161
|
}
|
|
162
|
+
offset += got;
|
|
163
|
+
const atEnd = offset >= totalSize;
|
|
164
|
+
if (atEnd) {
|
|
165
|
+
// 与 C++ 一致:尾块发出后紧跟 "close\n" 并断开
|
|
166
|
+
try { sock.write(buf.subarray(0, got)); sock.end('close\n'); } catch (e) {}
|
|
167
|
+
cleanup();
|
|
168
|
+
log(`[info] ${peer} 完成 ${filePath}`);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
158
171
|
if (!sock.write(buf.subarray(0, got))) {
|
|
159
|
-
// 背压:等 drain
|
|
172
|
+
// 背压:等 drain 再继续读下一行
|
|
160
173
|
sock.pause();
|
|
161
174
|
sock.once('drain', () => sock.resume());
|
|
162
175
|
}
|