-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
csi: Move convenience functions to fs module
- Loading branch information
Showing
15 changed files
with
137 additions
and
113 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
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
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,57 @@ | ||
//! Async CSI filesystem operations. | ||
use std::path::Path; | ||
|
||
use tokio::{fs::File, io}; | ||
|
||
use super::io::{Reader, Writer}; | ||
use crate::Index; | ||
|
||
/// Reads the entire contents of a coordinate-sorted index (CSI). | ||
/// | ||
/// This is a convenience function and is equivalent to opening the file at the given path and | ||
/// reading the index. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```no_run | ||
/// # #[tokio::main] | ||
/// # async fn main() -> tokio::io::Result<()> { | ||
/// use noodles_csi as csi; | ||
/// let index = csi::r#async::fs::read("sample.bcf.csi").await?; | ||
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
pub async fn read<P>(src: P) -> io::Result<Index> | ||
where | ||
P: AsRef<Path>, | ||
{ | ||
let mut reader = File::open(src).await.map(Reader::new)?; | ||
reader.read_index().await | ||
} | ||
|
||
/// Writes a coordinate-sorted index (CSI) to a file. | ||
/// | ||
/// This is a convenience function and is equivalent to creating a file at the given path and | ||
/// writing the index. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```no_run | ||
/// # #[tokio::main] | ||
/// # async fn main() -> tokio::io::Result<()> { | ||
/// use noodles_csi as csi; | ||
/// let index = csi::Index::default(); | ||
/// csi::r#async::fs::write("sample.bcf.csi", &index).await?; | ||
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
pub async fn write<P>(dst: P, index: &Index) -> io::Result<()> | ||
where | ||
P: AsRef<Path>, | ||
{ | ||
let mut writer = File::create(dst).await.map(Writer::new)?; | ||
writer.write_index(index).await?; | ||
writer.shutdown().await?; | ||
Ok(()) | ||
} |
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,49 @@ | ||
//! CSI filesystem operations. | ||
use std::{fs::File, io, path::Path}; | ||
|
||
use super::{ | ||
io::{Reader, Writer}, | ||
Index, | ||
}; | ||
|
||
/// Reads the entire contents of a coordinate-sorted index (CSI). | ||
/// | ||
/// This is a convenience function and is equivalent to opening the file at the given path and | ||
/// reading the index. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```no_run | ||
/// use noodles_csi as csi; | ||
/// let index = csi::fs::read("sample.bcf.csi")?; | ||
/// # Ok::<(), std::io::Error>(()) | ||
/// ``` | ||
pub fn read<P>(src: P) -> io::Result<Index> | ||
where | ||
P: AsRef<Path>, | ||
{ | ||
let mut reader = File::open(src).map(Reader::new)?; | ||
reader.read_index() | ||
} | ||
|
||
/// Writes a coordinate-sorted index (CSI) to a file. | ||
/// | ||
/// This is a convenience function and is equivalent to creating a file at the given path and | ||
/// writing the index. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```no_run | ||
/// use noodles_csi as csi; | ||
/// let index = csi::Index::default(); | ||
/// csi::fs::write("sample.bcf.csi", &index)?; | ||
/// # Ok::<(), std::io::Error>(()) | ||
/// ``` | ||
pub fn write<P>(dst: P, index: &Index) -> io::Result<()> | ||
where | ||
P: AsRef<Path>, | ||
{ | ||
let mut writer = File::create(dst).map(Writer::new)?; | ||
writer.write_index(index) | ||
} |
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
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