Struct autocompress::iothread::IoThread [−][src]
pub struct IoThread { /* fields omitted */ }
Expand description
Thread pool for I/O tasks
Implementations
Open file with multi threaded reader.
Example:
use autocompress::iothread::IoThread; let iothread = IoThread::new(2); let mut reader = iothread.open("testfiles/plain.txt.gz")?; let mut buffer = Vec::new(); reader.read_to_end(&mut buffer)?; assert_eq!(buffer, b"ABCDEFG\r\n1234567");
pub fn create<P: AsRef<Path>>(
&self,
path: P,
level: CompressionLevel
) -> Result<BlockWriter<'_, impl Write>>
pub fn create<P: AsRef<Path>>(
&self,
path: P,
level: CompressionLevel
) -> Result<BlockWriter<'_, impl Write>>
Creates file with multi threaded writer.
Example:
use autocompress::{iothread::IoThread, CompressionLevel}; let iothread = IoThread::new(2); let mut writer = iothread.create("target/block-writer1.txt.gz", CompressionLevel::Default)?; writer.write_all(b"ABCDEFG")?;
pub fn add_block_writer<W: Write + Send + 'static>(
&self,
writer: W,
block_compress: BlockCompress
) -> BlockWriter<'_, W>ⓘNotable traits for BlockWriter<'a, W>
impl<'a, W: Write + Send> Write for BlockWriter<'a, W>
pub fn add_block_writer<W: Write + Send + 'static>(
&self,
writer: W,
block_compress: BlockCompress
) -> BlockWriter<'_, W>ⓘNotable traits for BlockWriter<'a, W>
impl<'a, W: Write + Send> Write for BlockWriter<'a, W>
Creates new multi threaded compressor. This writer has buffers, so wrapping with std::io::BufWriter
is not required.
Example:
use autocompress::iothread::{IoThread, BlockCompress}; use autocompress::CompressionLevel; let mut gzip_block_compress = BlockCompress::gzip(CompressionLevel::Default); let file_writer = std::fs::File::create("target/block-writer2.txt.gz")?; let iothread = IoThread::new(1); let mut block_writer = iothread.add_block_writer(file_writer, gzip_block_compress); block_writer.write_all(b"ABCDEFG")?;
pub fn add_writer<W: Write + Send + 'static>(
&self,
writer: W
) -> ThreadWriter<'_, W>ⓘNotable traits for ThreadWriter<'a, W>
impl<'a, W: Write + Send> Write for ThreadWriter<'a, W>
pub fn add_writer<W: Write + Send + 'static>(
&self,
writer: W
) -> ThreadWriter<'_, W>ⓘNotable traits for ThreadWriter<'a, W>
impl<'a, W: Write + Send> Write for ThreadWriter<'a, W>
Register new writer and create threaded writer. Since each write requests cause inter thread communication,
wrapping with std::io::BufWriter
is recommended.
Example:
use autocompress::{iothread::IoThread, create, CompressionLevel}; use std::io::{prelude::*, self}; let nothread_writer = create("target/plain2.txt.xz", CompressionLevel::Default)?; let thread_pool = IoThread::new(2); let mut threaded_writer = thread_pool.add_writer(nothread_writer); threaded_writer.write_all(b"ABCDEFG\r\n1234567")?;
Register new writer and create threaded reader.
Example:
use autocompress::{iothread::IoThread, open}; use std::io::{prelude::*, self}; let nothread_reader = open("testfiles/plain.txt")?; let thread_pool = IoThread::new(2); let mut threaded_reader = thread_pool.add_reader(nothread_reader)?; let mut buffer = Vec::new(); threaded_reader.read_to_end(&mut buffer)?; assert_eq!(buffer, b"ABCDEFG\r\n1234567");
pub fn add_reader_with_capacity<R: Read + Send + 'static>(
&self,
reader: R,
capacity: usize
) -> Result<ThreadReader<'_, R>>
pub fn add_reader_with_capacity<R: Read + Send + 'static>(
&self,
reader: R,
capacity: usize
) -> Result<ThreadReader<'_, R>>
Register new writer and create threaded reader with buffer capacity.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for IoThread
impl !UnwindSafe for IoThread