-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bgzf/multithreaded_writer: Add builder
This also adds the ability to set the compression level. Closes #238.
- Loading branch information
Showing
5 changed files
with
85 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::{io::Write, num::NonZeroUsize}; | ||
|
||
use super::MultithreadedWriter; | ||
use crate::writer::CompressionLevel; | ||
|
||
/// A multithreaded BGZF writer builder. | ||
pub struct Builder { | ||
compression_level: CompressionLevel, | ||
worker_count: NonZeroUsize, | ||
} | ||
|
||
impl Builder { | ||
/// Sets the compression level. | ||
pub fn set_compression_level(mut self, compression_level: CompressionLevel) -> Self { | ||
self.compression_level = compression_level; | ||
self | ||
} | ||
|
||
/// Sets the worker count. | ||
pub fn set_worker_count(mut self, worker_count: NonZeroUsize) -> Self { | ||
self.worker_count = worker_count; | ||
self | ||
} | ||
|
||
/// Builds a multithreaded BGZF writer from a writer. | ||
pub fn build_from_writer<W>(self, writer: W) -> MultithreadedWriter | ||
where | ||
W: Write + Send + 'static, | ||
{ | ||
MultithreadedWriter::new(self.compression_level, self.worker_count, writer) | ||
} | ||
} | ||
|
||
impl Default for Builder { | ||
fn default() -> Self { | ||
Self { | ||
compression_level: CompressionLevel::default(), | ||
worker_count: NonZeroUsize::MIN, | ||
} | ||
} | ||
} |
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