Skip to content

Commit

Permalink
docs: update
Browse files Browse the repository at this point in the history
  • Loading branch information
hduprat-qare authored and kylefarris committed Oct 21, 2024
1 parent 39ea749 commit 594fb77
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
39 changes: 39 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ NodeClam class definition. To cf
* [.getVersion([cb])](#NodeClam+getVersion) ⇒ <code>Promise.&lt;string&gt;</code>
* [.isInfected(file, [cb])](#NodeClam+isInfected) ⇒ <code>Promise.&lt;object&gt;</code>
* [.passthrough()](#NodeClam+passthrough) ⇒ <code>Transform</code>
* [.ping([cb])](#NodeClam+ping) ⇒ <code>Promise.&lt;object&gt;</code>
* [.scanFile(file, [cb])](#NodeClam+scanFile) ⇒ <code>Promise.&lt;object&gt;</code>
* [.scanFiles(files, [endCb], [fileCb])](#NodeClam+scanFiles) ⇒ <code>Promise.&lt;object&gt;</code>
* [.scanDir(path, [endCb], [fileCb])](#NodeClam+scanDir) ⇒ <code>Promise.&lt;object&gt;</code>
Expand Down Expand Up @@ -250,6 +251,44 @@ output.on('finish', () => {

// NOTE: no errors (or other events) are being handled in this example but standard errors will be emitted according to NodeJS's Stream specifications
```

<a name="NodeClam+ping"></a>

### nodeClam.ping([cb]) ⇒ <code>Promise.&lt;object&gt;</code>
This method allows you to ping the socket. It supports a callback and Promise API.
If no callback is supplied, a Promise will be returned.

**Kind**: instance method of [<code>NodeClam</code>](#NodeClam)
**Returns**: <code>Promise.&lt;object&gt;</code> - A copy of the Socket/TCP client.

| Param | Type | Description |
| --- | --- | --- |
| [cb] | <code>function</code> | What to do after the ping |

**Example**
```js
// Callback Example
clamscan.ping((err, client) => {
if (err) return console.error(err);

console.log("ClamAV client is working");
client.end();
});

// Promise Example
clamscan.ping().then(client => {
console.log("ClamAV client is working");
client.end();
}).then(err => {
console.error(err);
});

// Async/Await Example
const client = await clamscan.ping();
console.log("ClamAV client is working");
client.end();
```

<a name="NodeClam+scanFile"></a>

### nodeClam.scanFile(file, [cb]) ⇒ <code>Promise.&lt;object&gt;</code>
Expand Down
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ If you are migrating from v0.8.5 or less to v1.0.0 or greater, please read the [
- [scanFiles](#scanFiles)
- [scanStream](#scanStream)
- [passthrough](#passthrough)
- [ping](#ping)
- [Contribute](#contribute)
- [Resources used to help develop this module](#resources-used-to-help-develop-this-module)

Expand Down Expand Up @@ -652,6 +653,66 @@ output.on('finish', () => {
// NOTE: no errors (or other events) are being handled in this example but standard errors will be emitted according to NodeJS's Stream specifications
```
<a name="ping"></a>
## .ping()
This method checks to see if the remote/local socket is working. It supports a callback and Promise API. If no callback is supplied, a Promise will be returned. This method can be used for healthcheck purposes and is already implicitly used during scan.
### Parameters
- `callback` (function) (optional) Will be called after the ping:
- `err` (object or null) A standard JavaScript Error object (null if no error)
- `client` (object) A copy of the Socket/TCP client
### Returns
- Promise
- Promise resolution returns: `client` (object): A copy of the Socket/TCP client
### Examples
**Callback Example:**
```javascript
const NodeClam = require('clamscan');

// You'll need to specify your socket or TCP connection info
const clamscan = new NodeClam().init({
clamdscan: {
socket: '/var/run/clamd.scan/clamd.sock',
host: '127.0.0.1',
port: 3310,
}
});

clamscan.ping((err, client) => {
if (err) return console.error(err);
console.log('ClamAV is still working!');
client.end();
});
```
**Promise Example:**
```javascript
clamscan.ping().then((client) => {
console.log('ClamAV is still working!');
client.end();
}).catch(err => {
console.error(err);
};
```
**Promise Example:**
```javascript
const client = await clamscan.ping();
client.end();
```
# Contribute
Got a missing feature you'd like to use? Found a bug? Go ahead and fork this repo, build the feature and issue a pull request.
Expand Down

0 comments on commit 594fb77

Please sign in to comment.