diff --git a/benches/decode_all.rs b/benches/decode_all.rs index 44455db0..08be96f5 100644 --- a/benches/decode_all.rs +++ b/benches/decode_all.rs @@ -1,5 +1,5 @@ use criterion::{criterion_group, criterion_main, Criterion}; -use ruzstd::FrameDecoder; +use ruzstd::decoding::frame_decoder::FrameDecoder; fn criterion_benchmark(c: &mut Criterion) { let mut fr = FrameDecoder::new(); diff --git a/fuzz/fuzz_targets/decode.rs b/fuzz/fuzz_targets/decode.rs index 4c88203e..2e60d8c2 100644 --- a/fuzz/fuzz_targets/decode.rs +++ b/fuzz/fuzz_targets/decode.rs @@ -1,10 +1,11 @@ #![no_main] -#[macro_use] extern crate libfuzzer_sys; +#[macro_use] +extern crate libfuzzer_sys; extern crate ruzstd; use std::io::Read; fuzz_target!(|data: &[u8]| { - if let Ok(mut decoder) = ruzstd::StreamingDecoder::new(data) { + if let Ok(mut decoder) = ruzstd::decoding::streaming_decoder::StreamingDecoder::new(data) { let mut output = Vec::new(); _ = decoder.read_to_end(&mut output); } diff --git a/fuzz/fuzz_targets/encode.rs b/fuzz/fuzz_targets/encode.rs index cbb4186d..5c763bee 100644 --- a/fuzz/fuzz_targets/encode.rs +++ b/fuzz/fuzz_targets/encode.rs @@ -1,7 +1,8 @@ #![no_main] -#[macro_use] extern crate libfuzzer_sys; +#[macro_use] +extern crate libfuzzer_sys; extern crate ruzstd; -use ruzstd::encoding::{FrameCompressor, CompressionLevel}; +use ruzstd::encoding::frame_compressor::{CompressionLevel, FrameCompressor}; fuzz_target!(|data: &[u8]| { let mut output = Vec::new(); @@ -9,7 +10,7 @@ fuzz_target!(|data: &[u8]| { compressor.compress(); let mut decoded = Vec::with_capacity(data.len()); - let mut decoder = ruzstd::FrameDecoder::new(); + let mut decoder = ruzstd::decoding::frame_decoder::FrameDecoder::new(); decoder.decode_all_to_vec(&output, &mut decoded).unwrap(); assert_eq!(data, &decoded); @@ -18,7 +19,7 @@ fuzz_target!(|data: &[u8]| { compressor.compress(); let mut decoded = Vec::with_capacity(data.len()); - let mut decoder = ruzstd::FrameDecoder::new(); + let mut decoder = ruzstd::decoding::frame_decoder::FrameDecoder::new(); decoder.decode_all_to_vec(&output, &mut decoded).unwrap(); assert_eq!(data, &decoded); -}); \ No newline at end of file +}); diff --git a/fuzz/fuzz_targets/fse.rs b/fuzz/fuzz_targets/fse.rs index 43efe777..b7e34e15 100644 --- a/fuzz/fuzz_targets/fse.rs +++ b/fuzz/fuzz_targets/fse.rs @@ -1,8 +1,9 @@ #![no_main] -#[macro_use] extern crate libfuzzer_sys; +#[macro_use] +extern crate libfuzzer_sys; extern crate ruzstd; use ruzstd::fse::round_trip; fuzz_target!(|data: &[u8]| { round_trip(data); -}); \ No newline at end of file +}); diff --git a/fuzz/fuzz_targets/huff0.rs b/fuzz/fuzz_targets/huff0.rs index b2dc806c..66ef425b 100644 --- a/fuzz/fuzz_targets/huff0.rs +++ b/fuzz/fuzz_targets/huff0.rs @@ -1,8 +1,9 @@ #![no_main] -#[macro_use] extern crate libfuzzer_sys; +#[macro_use] +extern crate libfuzzer_sys; extern crate ruzstd; use ruzstd::huff0::round_trip; fuzz_target!(|data: &[u8]| { round_trip(data); -}); \ No newline at end of file +}); diff --git a/fuzz/fuzz_targets/interop.rs b/fuzz/fuzz_targets/interop.rs index 00d2c90f..588e35b1 100644 --- a/fuzz/fuzz_targets/interop.rs +++ b/fuzz/fuzz_targets/interop.rs @@ -5,21 +5,21 @@ extern crate ruzstd; use std::io::Read; fn decode_ruzstd(data: &mut dyn std::io::Read) -> Vec { - let mut decoder = ruzstd::StreamingDecoder::new(data).unwrap(); + let mut decoder = ruzstd::decoding::streaming_decoder::StreamingDecoder::new(data).unwrap(); let mut result: Vec = Vec::new(); decoder.read_to_end(&mut result).expect("Decoding failed"); result } fn decode_ruzstd_writer(mut data: impl Read) -> Vec { - let mut decoder = ruzstd::FrameDecoder::new(); + let mut decoder = ruzstd::decoding::frame_decoder::FrameDecoder::new(); decoder.reset(&mut data).unwrap(); let mut result = vec![]; while !decoder.is_finished() || decoder.can_collect() > 0 { decoder .decode_blocks( &mut data, - ruzstd::BlockDecodingStrategy::UptoBytes(1024 * 1024), + ruzstd::decoding::frame_decoder::BlockDecodingStrategy::UptoBytes(1024 * 1024), ) .unwrap(); decoder.collect_to_writer(&mut result).unwrap(); @@ -35,7 +35,11 @@ fn encode_ruzstd_uncompressed(data: &mut dyn std::io::Read) -> Vec { let mut input = Vec::new(); let mut output = Vec::new(); data.read_to_end(&mut input).unwrap(); - let mut compressor = ruzstd::encoding::FrameCompressor::new(input.as_slice(), &mut output, ruzstd::encoding::CompressionLevel::Uncompressed); + let mut compressor = ruzstd::encoding::frame_compressor::FrameCompressor::new( + input.as_slice(), + &mut output, + ruzstd::encoding::frame_compressor::CompressionLevel::Uncompressed, + ); compressor.compress(); output } @@ -44,7 +48,11 @@ fn encode_ruzstd_compressed(data: &mut dyn std::io::Read) -> Vec { let mut input = Vec::new(); let mut output = Vec::new(); data.read_to_end(&mut input).unwrap(); - let mut compressor = ruzstd::encoding::FrameCompressor::new(input.as_slice(), &mut output, ruzstd::encoding::CompressionLevel::Fastest); + let mut compressor = ruzstd::encoding::frame_compressor::FrameCompressor::new( + input.as_slice(), + &mut output, + ruzstd::encoding::frame_compressor::CompressionLevel::Fastest, + ); compressor.compress(); output } diff --git a/src/bin/zstd.rs b/src/bin/zstd.rs index d6aebb7c..2288852a 100644 --- a/src/bin/zstd.rs +++ b/src/bin/zstd.rs @@ -7,10 +7,10 @@ use std::io::SeekFrom; use std::io::Write; use std::time::Instant; -use ruzstd::encoding::CompressionLevel; -use ruzstd::encoding::FrameCompressor; -use ruzstd::frame::ReadFrameHeaderError; -use ruzstd::frame_decoder::FrameDecoderError; +use ruzstd::decoding::frame::ReadFrameHeaderError; +use ruzstd::decoding::frame_decoder::FrameDecoderError; +use ruzstd::encoding::frame_compressor::CompressionLevel; +use ruzstd::encoding::frame_compressor::FrameCompressor; struct StateTracker { bytes_used: u64, @@ -41,7 +41,7 @@ fn decompress(flags: &[String], file_paths: &[String]) { return; } - let mut frame_dec = ruzstd::FrameDecoder::new(); + let mut frame_dec = ruzstd::decoding::frame_decoder::FrameDecoder::new(); for path in file_paths { eprintln!("File: {}", path); @@ -79,7 +79,12 @@ fn decompress(flags: &[String], file_paths: &[String]) { while !frame_dec.is_finished() { frame_dec - .decode_blocks(&mut f, ruzstd::BlockDecodingStrategy::UptoBytes(batch_size)) + .decode_blocks( + &mut f, + ruzstd::decoding::frame_decoder::BlockDecodingStrategy::UptoBytes( + batch_size, + ), + ) .unwrap(); if frame_dec.can_collect() > batch_size { diff --git a/src/bin/zstd_stream.rs b/src/bin/zstd_stream.rs index cb2ebc76..b25fe82f 100644 --- a/src/bin/zstd_stream.rs +++ b/src/bin/zstd_stream.rs @@ -30,7 +30,8 @@ fn main() { let f = File::open(path).unwrap(); let mut buf_read = std::io::BufReader::new(f); - let mut decoder = ruzstd::StreamingDecoder::new(&mut buf_read).unwrap(); + let mut decoder = + ruzstd::decoding::streaming_decoder::StreamingDecoder::new(&mut buf_read).unwrap(); let mut buf = [0u8; 1024 * 1024]; let mut stdout = std::io::stdout(); while !decoder.decoder.is_finished() || decoder.decoder.can_collect() > 0 { diff --git a/src/blocks/literals_section.rs b/src/blocks/literals_section.rs index 90e3c830..3a463e65 100644 --- a/src/blocks/literals_section.rs +++ b/src/blocks/literals_section.rs @@ -1,6 +1,7 @@ //! Utilities and representations for the first half of a block, the literals section. //! It contains data that is then copied from by the sequences section. -use super::super::decoding::bit_reader::{BitReader, GetBitsError}; +use crate::decoding::bit_reader::BitReader; +use crate::decoding::GetBitsError; /// A compressed block consists of two sections, a literals section, and a sequences section. /// diff --git a/src/decoding/bit_reader.rs b/src/decoding/bit_reader.rs index 425a017a..ed86491b 100644 --- a/src/decoding/bit_reader.rs +++ b/src/decoding/bit_reader.rs @@ -1,22 +1,11 @@ +use super::GetBitsError; + /// Interact with a provided source at a bit level. pub struct BitReader<'s> { idx: usize, //index counts bits already read source: &'s [u8], } -#[derive(Debug)] -#[non_exhaustive] -pub enum GetBitsError { - TooManyBits { - num_requested_bits: usize, - limit: u8, - }, - NotEnoughRemainingBits { - requested: usize, - remaining: usize, - }, -} - #[cfg(feature = "std")] impl std::error::Error for GetBitsError {} diff --git a/src/decoding/bit_reader_reverse.rs b/src/decoding/bit_reader_reverse.rs index 98546f4b..984d5684 100644 --- a/src/decoding/bit_reader_reverse.rs +++ b/src/decoding/bit_reader_reverse.rs @@ -1,7 +1,5 @@ -use core::convert::TryInto; - -pub use super::bit_reader::GetBitsError; use crate::io::Read; +use core::convert::TryInto; /// Zstandard encodes some types of data in a way that the data must be read /// back to front to decode it properly. `BitReaderReversed` provides a diff --git a/src/frame.rs b/src/decoding/frame.rs similarity index 100% rename from src/frame.rs rename to src/decoding/frame.rs diff --git a/src/frame_decoder.rs b/src/decoding/frame_decoder.rs similarity index 99% rename from src/frame_decoder.rs rename to src/decoding/frame_decoder.rs index ba86b593..69447691 100644 --- a/src/frame_decoder.rs +++ b/src/decoding/frame_decoder.rs @@ -1,6 +1,6 @@ //! Framedecoder is the man struct users interact with to decode zstd frames //! -//! Zstandard compressed data is made of one or more [Frame]s. Each frame is independent and can be +//! Zstandard compressed data is made of one or more [crate::decoding::frame::Frame]s. Each frame is independent and can be //! decompressed independently of other frames. This module contains structures //! and utilities that can be used to decode a frame. @@ -26,7 +26,7 @@ use std::error::Error as StdError; /// /// Workflow is as follows: /// ``` -/// use ruzstd::frame_decoder::BlockDecodingStrategy; +/// use ruzstd::decoding::frame_decoder::BlockDecodingStrategy; /// /// # #[cfg(feature = "std")] /// use std::io::{Read, Write}; @@ -37,7 +37,7 @@ use std::error::Error as StdError; /// /// fn decode_this(mut file: impl Read) { /// //Create a new decoder -/// let mut frame_dec = ruzstd::FrameDecoder::new(); +/// let mut frame_dec = ruzstd::decoding::frame_decoder::FrameDecoder::new(); /// let mut result = Vec::new(); /// /// // Use reset or init to make the decoder ready to decode the frame from the io::Read diff --git a/src/decoding/literals_section_decoder.rs b/src/decoding/literals_section_decoder.rs index 63301a66..c7a5400d 100644 --- a/src/decoding/literals_section_decoder.rs +++ b/src/decoding/literals_section_decoder.rs @@ -1,9 +1,10 @@ -//! This module contains the [decompress_literals] function, used to take a +//! This module contains the decompress_literals function, used to take a //! parsed literals header and a source and decompress it. use super::super::blocks::literals_section::{LiteralsSection, LiteralsSectionType}; -use super::bit_reader_reverse::{BitReaderReversed, GetBitsError}; +use super::bit_reader_reverse::BitReaderReversed; use super::scratch::HuffmanScratch; +use super::GetBitsError; use crate::huff0::{HuffmanDecoder, HuffmanDecoderError, HuffmanTableError}; use alloc::vec::Vec; diff --git a/src/decoding/mod.rs b/src/decoding/mod.rs index a9f9b7ae..4daa8fb9 100644 --- a/src/decoding/mod.rs +++ b/src/decoding/mod.rs @@ -6,9 +6,25 @@ pub mod bit_reader_reverse; pub mod block_decoder; pub mod decodebuffer; pub mod dictionary; +pub mod frame; +pub mod frame_decoder; pub mod literals_section_decoder; mod ringbuffer; #[allow(dead_code)] pub mod scratch; pub mod sequence_execution; pub mod sequence_section_decoder; +pub mod streaming_decoder; + +#[derive(Debug)] +#[non_exhaustive] +pub enum GetBitsError { + TooManyBits { + num_requested_bits: usize, + limit: u8, + }, + NotEnoughRemainingBits { + requested: usize, + remaining: usize, + }, +} diff --git a/src/decoding/sequence_section_decoder.rs b/src/decoding/sequence_section_decoder.rs index e7cc1944..553f9341 100644 --- a/src/decoding/sequence_section_decoder.rs +++ b/src/decoding/sequence_section_decoder.rs @@ -1,11 +1,12 @@ use super::super::blocks::sequence_section::ModeType; use super::super::blocks::sequence_section::Sequence; use super::super::blocks::sequence_section::SequencesHeader; -use super::bit_reader_reverse::{BitReaderReversed, GetBitsError}; +use super::bit_reader_reverse::BitReaderReversed; use super::scratch::FSEScratch; use crate::blocks::sequence_section::{ MAX_LITERAL_LENGTH_CODE, MAX_MATCH_LENGTH_CODE, MAX_OFFSET_CODE, }; +use crate::decoding::GetBitsError; use crate::fse::{FSEDecoder, FSEDecoderError, FSETableError}; use alloc::vec::Vec; diff --git a/src/streaming_decoder.rs b/src/decoding/streaming_decoder.rs similarity index 95% rename from src/streaming_decoder.rs rename to src/decoding/streaming_decoder.rs index fde7a9d9..dc72b9d6 100644 --- a/src/streaming_decoder.rs +++ b/src/decoding/streaming_decoder.rs @@ -1,6 +1,6 @@ use core::borrow::BorrowMut; -use crate::frame_decoder::{BlockDecodingStrategy, FrameDecoder, FrameDecoderError}; +use crate::decoding::frame_decoder::{BlockDecodingStrategy, FrameDecoder, FrameDecoderError}; use crate::io::{Error, ErrorKind, Read}; /// High level Zstandard frame decoder that can be used to decompress a given Zstandard frame. @@ -19,7 +19,7 @@ use crate::io::{Error, ErrorKind, Read}; /// /// To decode all the frames in a finite stream, the calling code needs to recreate /// the instance of the decoder and handle -/// [crate::frame::ReadFrameHeaderError::SkipFrame] +/// [crate::decoding::frame::ReadFrameHeaderError::SkipFrame] /// errors by skipping forward the `length` amount of bytes, see /// /// ```no_run @@ -28,7 +28,7 @@ use crate::io::{Error, ErrorKind, Read}; /// { /// use std::fs::File; /// use std::io::Read; -/// use ruzstd::{StreamingDecoder}; +/// use ruzstd::decoding::streaming_decoder::StreamingDecoder; /// /// // Read a Zstandard archive from the filesystem then decompress it into a vec. /// let mut f: File = todo!("Read a .zstd archive from somewhere"); diff --git a/src/encoding/frame_encoder.rs b/src/encoding/frame_compressor.rs similarity index 96% rename from src/encoding/frame_encoder.rs rename to src/encoding/frame_compressor.rs index deb275b0..fc117957 100644 --- a/src/encoding/frame_encoder.rs +++ b/src/encoding/frame_compressor.rs @@ -45,7 +45,7 @@ pub enum CompressionLevel { /// /// # Examples /// ``` -/// use ruzstd::encoding::{FrameCompressor, CompressionLevel}; +/// use ruzstd::encoding::frame_compressor::{FrameCompressor, CompressionLevel}; /// let mock_data: &[_] = &[0x1, 0x2, 0x3, 0x4]; /// let mut output = std::vec::Vec::new(); /// // Initialize a compressor. @@ -190,7 +190,7 @@ mod tests { use alloc::vec; use super::FrameCompressor; - use crate::{frame::MAGIC_NUM, FrameDecoder}; + use crate::decoding::{frame::MAGIC_NUM, frame_decoder::FrameDecoder}; use alloc::vec::Vec; #[test] @@ -286,21 +286,24 @@ mod tests { fn fuzz_targets() { use std::io::Read; fn decode_ruzstd(data: &mut dyn std::io::Read) -> Vec { - let mut decoder = crate::StreamingDecoder::new(data).unwrap(); + let mut decoder = + crate::decoding::streaming_decoder::StreamingDecoder::new(data).unwrap(); let mut result: Vec = Vec::new(); decoder.read_to_end(&mut result).expect("Decoding failed"); result } fn decode_ruzstd_writer(mut data: impl Read) -> Vec { - let mut decoder = crate::FrameDecoder::new(); + let mut decoder = crate::decoding::frame_decoder::FrameDecoder::new(); decoder.reset(&mut data).unwrap(); let mut result = vec![]; while !decoder.is_finished() || decoder.can_collect() > 0 { decoder .decode_blocks( &mut data, - crate::BlockDecodingStrategy::UptoBytes(1024 * 1024), + crate::decoding::frame_decoder::BlockDecodingStrategy::UptoBytes( + 1024 * 1024, + ), ) .unwrap(); decoder.collect_to_writer(&mut result).unwrap(); diff --git a/src/encoding/frame_header.rs b/src/encoding/frame_header.rs index beadf2b1..72ef4061 100644 --- a/src/encoding/frame_header.rs +++ b/src/encoding/frame_header.rs @@ -1,9 +1,9 @@ //! Utilities and representations for a frame header. +use crate::decoding::frame; use crate::encoding::{ bit_writer::BitWriter, util::{find_min_size, minify_val}, }; -use crate::frame; use alloc::vec::Vec; /// A header for a single Zstandard frame. @@ -162,7 +162,7 @@ fn minify_val_fcs(val: u64) -> Vec { #[cfg(test)] mod tests { use super::FrameHeader; - use crate::frame::{read_frame_header, FrameDescriptor}; + use crate::decoding::frame::{read_frame_header, FrameDescriptor}; use alloc::vec::Vec; #[test] diff --git a/src/encoding/mod.rs b/src/encoding/mod.rs index 357776ca..83d7e014 100644 --- a/src/encoding/mod.rs +++ b/src/encoding/mod.rs @@ -3,19 +3,20 @@ pub(crate) mod bit_writer; pub(crate) mod block_header; pub(crate) mod blocks; -mod frame_encoder; pub(crate) mod frame_header; pub(crate) mod match_generator; pub(crate) mod util; +pub mod frame_compressor; + use crate::io::{Read, Write}; use alloc::vec::Vec; -pub use frame_encoder::*; +use frame_compressor::{CompressionLevel, FrameCompressor}; use match_generator::Sequence; /// Convenience function to compress some source into a target without reusing any resources of the compressor /// ```rust -/// use ruzstd::encoding::{compress, CompressionLevel}; +/// use ruzstd::encoding::{compress, frame_compressor::CompressionLevel}; /// let data: &[u8] = &[0,0,0,0,0,0,0,0,0,0,0,0]; /// let mut target = Vec::new(); /// compress(data, &mut target, CompressionLevel::Fastest); @@ -27,7 +28,7 @@ pub fn compress(source: R, target: W, level: CompressionLevel /// Convenience function to compress some source into a target without reusing any resources of the compressor into a Vec /// ```rust -/// use ruzstd::encoding::{compress_to_vec, CompressionLevel}; +/// use ruzstd::encoding::{compress_to_vec, frame_compressor::CompressionLevel}; /// let data: &[u8] = &[0,0,0,0,0,0,0,0,0,0,0,0]; /// let compressed = compress_to_vec(data, CompressionLevel::Fastest); /// ``` diff --git a/src/fse/fse_decoder.rs b/src/fse/fse_decoder.rs index 45adc931..3fbf94c4 100644 --- a/src/fse/fse_decoder.rs +++ b/src/fse/fse_decoder.rs @@ -1,5 +1,6 @@ use crate::decoding::bit_reader::BitReader; -use crate::decoding::bit_reader_reverse::{BitReaderReversed, GetBitsError}; +use crate::decoding::bit_reader_reverse::BitReaderReversed; +use crate::decoding::GetBitsError; use alloc::vec::Vec; /// FSE decoding involves a decoding table that describes the probabilities of diff --git a/src/huff0/huff0_decoder.rs b/src/huff0/huff0_decoder.rs index e7d98446..13412f01 100644 --- a/src/huff0/huff0_decoder.rs +++ b/src/huff0/huff0_decoder.rs @@ -1,6 +1,7 @@ //! Utilities for decoding Huff0 encoded huffman data. -use crate::decoding::bit_reader_reverse::{BitReaderReversed, GetBitsError}; +use crate::decoding::bit_reader_reverse::BitReaderReversed; +use crate::decoding::GetBitsError; use crate::fse::{FSEDecoder, FSEDecoderError, FSETable, FSETableError}; use alloc::vec::Vec; #[cfg(feature = "std")] diff --git a/src/lib.rs b/src/lib.rs index ee00bad3..c80dc999 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,11 +3,12 @@ //! # Getting Started //! ## Decompression //! The [decoding] module contains the internals for decompression. -//! Decompression can be achieved by using the [`StreamingDecoder`] interface. +//! Decompression can be achieved by using the [`decoding::streaming_decoder::StreamingDecoder`] interface +//! or the more low-level [`decoding::frame_decoder::FrameDecoder`] //! //! ## Compression //! The [encoding] module contains the internals for compression. -//! Decompression can be achieved by using the [`encoding::compress`]/[`encoding::compress_to_vec`] functions or the [`FrameCompressor`] interface. +//! Decompression can be achieved by using the [`encoding::compress`]/[`encoding::compress_to_vec`] functions or the [`encoding::frame_compressor::FrameCompressor`] interface. //! //! # Speed //! The decoder has been measured to be roughly between 3.5 to 1.4 times slower @@ -36,11 +37,8 @@ macro_rules! vprintln { pub mod blocks; pub mod decoding; pub mod encoding; -pub mod frame; -pub mod frame_decoder; pub mod fse; pub mod huff0; -pub mod streaming_decoder; mod tests; #[cfg(feature = "std")] @@ -51,9 +49,3 @@ pub mod io_nostd; #[cfg(not(feature = "std"))] pub use io_nostd as io; - -pub use frame_decoder::BlockDecodingStrategy; -pub use frame_decoder::FrameDecoder; -pub use streaming_decoder::StreamingDecoder; - -pub use encoding::FrameCompressor; diff --git a/src/tests/decode_corpus.rs b/src/tests/decode_corpus.rs index c6fb888c..b17ff6d3 100644 --- a/src/tests/decode_corpus.rs +++ b/src/tests/decode_corpus.rs @@ -1,7 +1,7 @@ #[test] fn test_decode_corpus_files() { extern crate std; - use crate::frame_decoder; + use crate::decoding::frame_decoder; use alloc::borrow::ToOwned; use alloc::string::{String, ToString}; use alloc::vec::Vec; diff --git a/src/tests/dict_test.rs b/src/tests/dict_test.rs index 1c2993d4..f46de539 100644 --- a/src/tests/dict_test.rs +++ b/src/tests/dict_test.rs @@ -77,7 +77,7 @@ fn test_dict_parsing() { #[test] fn test_dict_decoding() { extern crate std; - use crate::frame_decoder; + use crate::decoding::frame_decoder; use alloc::borrow::ToOwned; use alloc::string::{String, ToString}; use alloc::vec::Vec; diff --git a/src/tests/encode_corpus.rs b/src/tests/encode_corpus.rs index e8000e2a..1c9de577 100644 --- a/src/tests/encode_corpus.rs +++ b/src/tests/encode_corpus.rs @@ -1,7 +1,7 @@ #[test] fn test_encode_corpus_files_uncompressed_our_decompressor() { extern crate std; - use crate::encoding::FrameCompressor; + use crate::encoding::frame_compressor::FrameCompressor; use alloc::borrow::ToOwned; use alloc::vec::Vec; use std::ffi::OsStr; @@ -34,12 +34,13 @@ fn test_encode_corpus_files_uncompressed_our_decompressor() { let mut compressor = FrameCompressor::new( input.as_slice(), &mut compressed_file, - crate::encoding::CompressionLevel::Fastest, + crate::encoding::frame_compressor::CompressionLevel::Fastest, ); compressor.compress(); let mut decompressed_output = Vec::new(); let mut decoder = - crate::streaming_decoder::StreamingDecoder::new(compressed_file.as_slice()).unwrap(); + crate::decoding::streaming_decoder::StreamingDecoder::new(compressed_file.as_slice()) + .unwrap(); decoder.read_to_end(&mut decompressed_output).unwrap(); if input != decompressed_output { @@ -58,7 +59,7 @@ fn test_encode_corpus_files_uncompressed_our_decompressor() { #[test] fn test_encode_corpus_files_uncompressed_original_decompressor() { extern crate std; - use crate::encoding::FrameCompressor; + use crate::encoding::frame_compressor::FrameCompressor; use alloc::borrow::ToOwned; use alloc::format; use alloc::vec::Vec; @@ -91,7 +92,7 @@ fn test_encode_corpus_files_uncompressed_original_decompressor() { let mut compressor = FrameCompressor::new( input.as_slice(), &mut compressed_file, - crate::encoding::CompressionLevel::Fastest, + crate::encoding::frame_compressor::CompressionLevel::Fastest, ); compressor.compress(); let mut decompressed_output = Vec::new(); @@ -122,7 +123,7 @@ fn test_encode_corpus_files_uncompressed_original_decompressor() { #[test] fn test_encode_corpus_files_compressed_our_decompressor() { extern crate std; - use crate::encoding::FrameCompressor; + use crate::encoding::frame_compressor::FrameCompressor; use alloc::borrow::ToOwned; use alloc::vec::Vec; use std::ffi::OsStr; @@ -154,12 +155,13 @@ fn test_encode_corpus_files_compressed_our_decompressor() { let mut compressor = FrameCompressor::new( input.as_slice(), &mut compressed_file, - crate::encoding::CompressionLevel::Fastest, + crate::encoding::frame_compressor::CompressionLevel::Fastest, ); compressor.compress(); let mut decompressed_output = Vec::new(); let mut decoder = - crate::streaming_decoder::StreamingDecoder::new(compressed_file.as_slice()).unwrap(); + crate::decoding::streaming_decoder::StreamingDecoder::new(compressed_file.as_slice()) + .unwrap(); decoder.read_to_end(&mut decompressed_output).unwrap(); if input != decompressed_output { @@ -178,7 +180,7 @@ fn test_encode_corpus_files_compressed_our_decompressor() { #[test] fn test_encode_corpus_files_compressed_original_decompressor() { extern crate std; - use crate::encoding::FrameCompressor; + use crate::encoding::frame_compressor::FrameCompressor; use alloc::borrow::ToOwned; use alloc::format; use alloc::vec::Vec; @@ -211,7 +213,7 @@ fn test_encode_corpus_files_compressed_original_decompressor() { let mut compressor = FrameCompressor::new( input.as_slice(), &mut compressed_file, - crate::encoding::CompressionLevel::Fastest, + crate::encoding::frame_compressor::CompressionLevel::Fastest, ); compressor.compress(); let mut decompressed_output = Vec::new(); diff --git a/src/tests/fuzz_regressions.rs b/src/tests/fuzz_regressions.rs index e068bd90..088b09ed 100644 --- a/src/tests/fuzz_regressions.rs +++ b/src/tests/fuzz_regressions.rs @@ -1,7 +1,7 @@ #[test] fn test_all_artifacts() { extern crate std; - use crate::frame_decoder; + use crate::decoding::frame_decoder; use std::borrow::ToOwned; use std::fs; use std::fs::File; diff --git a/src/tests/mod.rs b/src/tests/mod.rs index b073258c..298c6c6c 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -28,7 +28,7 @@ impl crate::io_nostd::Read for std::fs::File { fn assure_error_impl() { // not a real test just there to throw an compiler error if Error is not derived correctly - use crate::frame_decoder::FrameDecoderError; + use crate::decoding::frame_decoder::FrameDecoderError; let _err: &dyn std::error::Error = &FrameDecoderError::NotYetInitialized; } @@ -37,7 +37,7 @@ fn assure_error_impl() { fn assure_decoder_send_sync() { // not a real test just there to throw an compiler error if FrameDecoder is Send + Sync - use crate::frame_decoder::FrameDecoder; + use crate::decoding::frame_decoder::FrameDecoder; let decoder = FrameDecoder::new(); std::thread::spawn(move || { drop(decoder); @@ -46,7 +46,7 @@ fn assure_decoder_send_sync() { #[test] fn skippable_frame() { - use crate::frame; + use crate::decoding::frame; let mut content = vec![]; content.extend_from_slice(&0x184D2A50u32.to_le_bytes()); @@ -78,7 +78,7 @@ fn skippable_frame() { #[cfg(test)] #[test] fn test_frame_header_reading() { - use crate::frame; + use crate::decoding::frame; use std::fs; let mut content = fs::File::open("./decodecorpus_files/z000088.zst").unwrap(); @@ -88,7 +88,7 @@ fn test_frame_header_reading() { #[test] fn test_block_header_reading() { use crate::decoding; - use crate::frame; + use crate::decoding::frame; use std::fs; let mut content = fs::File::open("./decodecorpus_files/z000088.zst").unwrap(); @@ -101,7 +101,7 @@ fn test_block_header_reading() { #[test] fn test_frame_decoder() { - use crate::frame_decoder; + use crate::decoding::frame_decoder; use std::fs; let mut content = fs::File::open("./decodecorpus_files/z000088.zst").unwrap(); @@ -126,7 +126,7 @@ fn test_frame_decoder() { #[test] fn test_decode_from_to() { - use crate::frame_decoder; + use crate::decoding::frame_decoder; use std::fs::File; use std::io::Read; let f = File::open("./decodecorpus_files/z000088.zst").unwrap(); @@ -228,7 +228,7 @@ fn test_decode_from_to() { #[test] fn test_specific_file() { - use crate::frame_decoder; + use crate::decoding::frame_decoder; use std::fs; use std::io::Read; @@ -293,7 +293,8 @@ fn test_streaming() { use std::io::Read; let mut content = fs::File::open("./decodecorpus_files/z000088.zst").unwrap(); - let mut stream = crate::streaming_decoder::StreamingDecoder::new(&mut content).unwrap(); + let mut stream = + crate::decoding::streaming_decoder::StreamingDecoder::new(&mut content).unwrap(); let mut result = Vec::new(); Read::read_to_end(&mut stream, &mut result).unwrap(); @@ -331,7 +332,7 @@ fn test_streaming() { // Test resetting to a new file while keeping the old decoder let mut content = fs::File::open("./decodecorpus_files/z000068.zst").unwrap(); - let mut stream = crate::streaming_decoder::StreamingDecoder::new_with_decoder( + let mut stream = crate::decoding::streaming_decoder::StreamingDecoder::new_with_decoder( &mut content, stream.into_frame_decoder(), ) @@ -375,7 +376,7 @@ fn test_streaming() { #[test] fn test_incremental_read() { - use crate::frame_decoder::FrameDecoder; + use crate::decoding::frame_decoder::FrameDecoder; let mut unread_compressed_content = include_bytes!("../../decodecorpus_files/abc.txt.zst").as_slice(); @@ -483,7 +484,7 @@ fn test_streaming_no_std() { #[test] fn test_decode_all() { - use crate::frame_decoder::{FrameDecoder, FrameDecoderError}; + use crate::decoding::frame_decoder::{FrameDecoder, FrameDecoderError}; let skip_frame = |input: &mut Vec, length: usize| { input.extend_from_slice(&0x184D2A50u32.to_le_bytes());