Skip to content

Commit

Permalink
Add usage with async-std section
Browse files Browse the repository at this point in the history
  • Loading branch information
toblux committed Feb 27, 2024
1 parent 4efc332 commit 48439e9
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ if data_clean {
assert!(!data_clean);
```

### Usage - Async with Tokio
### Usage - Async with `tokio`

```rust
#[cfg(feature = "tokio-stream")]
Expand Down Expand Up @@ -140,6 +140,39 @@ tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().bloc
})
```

### Usage - Async with `async-std`

```rust
#[cfg(feature = "async-std")]
async_std::task::block_on(async {
let clamd_host_address = "localhost:3310";

// Ping clamd asynchronously and await the result
let clamd_available = match clamav_client::async_std::ping_tcp(clamd_host_address).await {
Ok(ping_response) => ping_response == clamav_client::PONG,
Err(_) => false,
};

if !clamd_available {
println!("Cannot ping clamd at {}", clamd_host_address);
return;
}
assert!(clamd_available);

// Scan a file for viruses
let file_path = "tests/data/eicar.txt";
let scan_file_result = clamav_client::async_std::scan_file_tcp(file_path, clamd_host_address, None).await;
let scan_file_response = scan_file_result.unwrap();
let file_clean = clamav_client::clean(&scan_file_response).unwrap();
if file_clean {
println!("No virus found in {}", file_path);
} else {
println!("The file {} is infected!", file_path);
}
assert!(!file_clean);
})
```

More examples can be found in the [tests](tests/clamav_client.rs).

## Links
Expand Down

0 comments on commit 48439e9

Please sign in to comment.