Comments (6)
Actually, I think there might be an issue with your code...
In the following section, you're doing a Promise.all()
but you don't need to since the map you're running doesn't return any unresolved promises. In fact, it doesn't return anything (which is invalid).
const clamscan = await this.clamscan.init(this.config.clamscan);
await Promise.all(
mail.attachments.map(async (attachment, i) => {
try {
const stream = isStream(attachment.content)
? attachment.content
: intoStream(attachment.content);
const {
is_infected: isInfected,
viruses
} = await clamscan.scan_stream(stream);
const name = isSANB(attachment.filename)
? `"${attachment.filename}"`
: `#${i + 1}`;
if (isInfected)
messages.push(
`Attachment ${name} was infected with "${viruses}".`
);
} catch (err) {
this.config.logger.error(err);
}
})
);
Something along these lines might be better...
const clamscan = await this.clamscan.init(this.config.clamscan);
try {
const results = await Promise.all(
mail.attachments.map((attachment, i) => {
const stream = isStream(attachment.content)
? attachment.content
: intoStream(attachment.content);
return clamscan.scan_stream(stream);
})
);
results.forEach((result, i) => {
const attachment = mail.attachments[i];
const name = isSANB(attachment.filename)
? `"${attachment.filename}"`
: `#${i + 1}`;
if (result.isInfected)
messages.push(
`Attachment ${name} was infected with "${result.viruses}".`
);
});
} catch (err) {
this.config.logger.error(err);
}
Let me know if that helps at all.
from clamscan.
Did this help at all? I'm inclined to close this ticket in a few days under the assumption that you've figured out what's going on.
from clamscan.
No, that did not help. You can use await Promise.all
even if you don't return anything, that's totally valid.
from clamscan.
You’re misunderstanding what I’m saying. It’s not the Promise.all
that’s the problem, it’s you’re map
. Nothing is actually going into your Promise.all
method because the map isn’t retuning anything.
The way you currently have it, you might as well just run a forEach
loop and skip the Promise.all
altogether.
from clamscan.
FWIW, I just wrote some tests to verify that the specific scenario you have is working and the tests pass. You can see the new tests here:
Lines 1262 to 1302 in 7ea77ae
There may be something else going on in your code but I'm not sure how to help beyond this. As far as I can test, the clamscan
module is working fine. If you can provide a simplified repeatable test script showing that this module isn't working as expected, I'd be more than happy to address it (pull requests are also welcome as always).
from clamscan.
Thanks for following up here, will close, and follow up if I see it again.
from clamscan.
Related Issues (20)
- Frequent failed clamAV scan fails HOT 2
- Premature end of ClamAV socket stream behind telepresence proxy HOT 18
- Clamav file size limit - throw custom error HOT 10
- Socket times out when remote scanning EICAR test file HOT 7
- node-clam: Could not verify the clamdscan binary HOT 2
- scanStream returning isInfected = true even when its not HOT 4
- Receiving null response from ScanFile HOT 2
- Missing error handler for tcp client
- TypeError: clamscan.isInfected is not a function HOT 1
- Retry on ECONNREFUSED for ClamAV using TCP sockets HOT 1
- No/Empty Response HOT 1
- Virus analysis tools should use local heuristical analysis/sandboxes plus artificial CNS HOT 4
- NodeClamError: There was an issue scanning the path specified! HOT 1
- node 16 and aws-sdk HOT 2
- Clam API Server HOT 1
- Occasionally getting the 502 Proxy error while running this clamscan service on the Prod server. HOT 3
- scanDir do not return an array of files HOT 10
- Fix code scanning alert - Inefficient regular expression
- execFile & Clamdscan result parsing HOT 4
- Chunked passthrough? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clamscan.