Skip to content

Commit

Permalink
Fixed the issue that the socket is closed too early (kylefarris#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
mihui committed Jul 16, 2024
1 parent 77c85dc commit 17b05e7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2247,15 +2247,35 @@ class NodeClam {
socket = await this._initSocket('scanStream');

// Pipe the stream through our transform and into the ClamAV socket
stream.pipe(transform).pipe(socket);
// stream.pipe(transform).pipe(socket);
transform
// Writing data into ClamAV socket
.on('data', data => {
socket.write(data);
})
// The transform stream has dried up
.on('end', () => {
if (this.settings.debugMode) console.log(`${this.debugLabel}: The transform stream has ended.`);
})
.on('error', err => {
console.error(`${this.debugLabel}: Error emitted from transform stream: `, err);
socket.end();
return hasCb ? cb(err, null) : reject(err);
});

// Setup the listeners for the stream
stream
// The stream is writting data into transform stream
.on('data', data => {
transform.write(data);
})
// The stream has dried up
.on('end', () => {
if (this.settings.debugMode) console.log(`${this.debugLabel}: The input stream has dried up.`);
finished = true;
stream.destroy();
socket.destroy();
transform.destroy();
})
// There was an error with the stream (ex. uploader closed browser)
.on('error', (err) => {
Expand Down

0 comments on commit 17b05e7

Please sign in to comment.