-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#![warn(rust_2018_idioms)] | ||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASM does support this, but it is nightly | ||
|
||
use tempfile::tempdir; | ||
use tokio::fs; | ||
use tokio::io::AsyncSeekExt; | ||
|
||
#[tokio::test] | ||
async fn read_at() { | ||
let temp_dir = tempdir().unwrap(); | ||
let file_path = temp_dir.path().join("a.txt"); | ||
fs::write(&file_path, b"HelloWorld").await.unwrap(); | ||
let mut file = fs::File::open(file_path.as_path()).await.unwrap(); | ||
|
||
let mut buf = [0_u8; 10]; | ||
assert_eq!(file.read_at(&mut buf, 5).await.unwrap(), 5); | ||
assert_eq!(&buf[..5], b"World"); | ||
|
||
assert_eq!(file.stream_position().await.unwrap(), 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#![warn(rust_2018_idioms)] | ||
#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASM does support this, but it is nightly | ||
|
||
use tempfile::tempdir; | ||
use tokio::fs; | ||
use tokio::fs::OpenOptions; | ||
use tokio::io::AsyncSeekExt; | ||
|
||
#[tokio::test] | ||
async fn write_at() { | ||
let temp_dir = tempdir().unwrap(); | ||
let file_path = temp_dir.path().join("a.txt"); | ||
fs::write(&file_path, b"Hello File").await.unwrap(); | ||
let mut file = OpenOptions::new() | ||
.write(true) | ||
.open(file_path.as_path()) | ||
.await | ||
.unwrap(); | ||
|
||
assert_eq!(file.write_at(b"World", 5).await.unwrap(), 5); | ||
let contents = fs::read(file_path.as_path()).await.unwrap(); | ||
assert_eq!(contents, b"HelloWorld"); | ||
|
||
assert_eq!(file.stream_position().await.unwrap(), 0); | ||
} |