Debian Codegraph @

src/bulk/decompressor.rs

raw symbols SCIP
1 use craterust-analyzer cargo zstd 0.13.3 crate/::map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().;
2
3 #[cfg(feature = "experimental")]
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryIntorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#;
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/;
6 use zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/;
7
8 /// Allows to decompress independently multiple blocks of data.
9 ///
10 /// This reduces memory usage compared to calling `decompress` multiple times.
11 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
12 pub struct Decompressorrust-analyzer cargo zstd 0.13.3 bulk/decompressor/Decompressor#<'a> {
13 contextrust-analyzer cargo zstd 0.13.3 bulk/decompressor/Decompressor#context.: zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::DCtxrust-analyzer cargo zstd-safe 7.2.2 DCtx#<'a>,
14 }
15
16 impl Decompressorrust-analyzer cargo zstd 0.13.3 bulk/decompressor/Decompressor#<'static> {
17 /// Creates a new zstd decompressor.
18 pub fn newrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'static>`]new().() -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Selfrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'static>`]> {
19 Selfrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'static>`]::with_dictionaryrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'static>`]with_dictionary().(&[])
20 }
21
22 /// Creates a new zstd decompressor, using the given dictionary.
23 pub fn with_dictionaryrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'static>`]with_dictionary().(dictionary: &[u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Selfrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'static>`]> {
24 let mut decompressor = Selfrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'static>`]::defaultrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'a>`][Default]default().();
25
26 decompressor.set_dictionaryrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'a>`]set_dictionary().(dictionary)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
27
28 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(decompressor)
29 }
30 }
31
32 impl<'a> Decompressorrust-analyzer cargo zstd 0.13.3 bulk/decompressor/Decompressor#<'a> {
33 /// Creates a new decompressor using an existing `DecoderDictionary`.
34 ///
35 /// Note that using a dictionary means that compression will need to use
36 /// the same dictionary.
37 pub fn with_prepared_dictionaryrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'a>`]with_prepared_dictionary().<'b>(
38 dictionary: &'a craterust-analyzer cargo zstd 0.13.3 crate/::dictrust-analyzer cargo zstd 0.13.3 dict/::DecoderDictionaryrust-analyzer cargo zstd 0.13.3 dict/DecoderDictionary#<'b>,
39 ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Selfrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'a>`]>
40 where
41 'b: 'a,
42 {
43 let mut decompressor = Selfrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'a>`]::defaultrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'a>`][Default]default().();
44
45 decompressor.set_prepared_dictionaryrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'a>`]set_prepared_dictionary().(dictionary)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
46
47 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(decompressor)
48 }
49
50 /// Changes the dictionary used by this decompressor.
51 ///
52 /// Will affect future compression jobs.
53 ///
54 /// Note that using a dictionary means that compression will need to use
55 /// the same dictionary.
56 pub fn set_dictionaryrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'a>`]set_dictionary().(&mut self, dictionary: &[u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
57 self.contextrust-analyzer cargo zstd 0.13.3 bulk/decompressor/Decompressor#context.
58 .load_dictionaryrust-analyzer cargo zstd-safe 7.2.2 impl#[`DCtx<'a>`]load_dictionary().(dictionary)
59 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
60
61 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
62 }
63
64 /// Changes the dictionary used by this decompressor.
65 ///
66 /// Note that using a dictionary means that compression will need to use
67 /// the same dictionary.
68 pub fn set_prepared_dictionaryrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'a>`]set_prepared_dictionary().<'b>(
69 &mut self,
70 dictionary: &'a craterust-analyzer cargo zstd 0.13.3 crate/::dictrust-analyzer cargo zstd 0.13.3 dict/::DecoderDictionaryrust-analyzer cargo zstd 0.13.3 dict/DecoderDictionary#<'b>,
71 ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()>
72 where
73 'b: 'a,
74 {
75 self.contextrust-analyzer cargo zstd 0.13.3 bulk/decompressor/Decompressor#context.
76 .ref_ddictrust-analyzer cargo zstd-safe 7.2.2 impl#[`DCtx<'a>`]ref_ddict().(dictionary.as_ddictrust-analyzer cargo zstd 0.13.3 dict/impl#[`DecoderDictionary<'a>`]as_ddict().())
77 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
78
79 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
80 }
81
82 /// Deompress a single block of data to the given destination buffer.
83 ///
84 /// Returns the number of bytes written, or an error if something happened
85 /// (for instance if the destination buffer was too small).
86 pub fn decompress_to_bufferrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'a>`]decompress_to_buffer().<C: zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::WriteBufrust-analyzer cargo zstd-safe 7.2.2 WriteBuf# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(
87 &mut self,
88 source: &[u8],
89 destination: &mut C,
90 ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> {
91 self.contextrust-analyzer cargo zstd 0.13.3 bulk/decompressor/Decompressor#context.
92 .decompressrust-analyzer cargo zstd-safe 7.2.2 impl#[`DCtx<'a>`]decompress().(destination, source)
93 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().)
94 }
95
96 /// Decompress a block of data, and return the result in a `Vec<u8>`.
97 ///
98 /// The decompressed data should be at most `capacity` bytes,
99 /// or an error will be returned.
100 pub fn decompressrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'a>`]decompress().(
101 &mut self,
102 data: &[u8],
103 capacity: usize,
104 ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> {
105 let capacity =
106 Selfrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'a>`]::upper_boundrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'a>`]upper_bound().(data).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(capacity).minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#min().(capacity);
107 let mut buffer = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(capacity);
108 self.decompress_to_bufferrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'a>`]decompress_to_buffer().(data, &mut buffer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
109 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(buffer)
110 }
111
112 /// Sets a decompression parameter for this decompressor.
113 pub fn set_parameterrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'a>`]set_parameter().(
114 &mut self,
115 parameter: zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::DParameterrust-analyzer cargo zstd-safe 7.2.2 DParameter#,
116 ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
117 self.contextrust-analyzer cargo zstd 0.13.3 bulk/decompressor/Decompressor#context.
118 .set_parameterrust-analyzer cargo zstd-safe 7.2.2 impl#[`DCtx<'a>`]set_parameter().(parameter)
119 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
120 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
121 }
122
123 craterust-analyzer cargo zstd 0.13.3 crate/::decoder_parametersrust-analyzer cargo zstd 0.13.3 stream/decoder_parameters!!();
124
125 /// Get an upper bound on the decompressed size of data, if available
126 ///
127 /// This can be used to pre-allocate enough capacity for `decompress_to_buffer`
128 /// and is used by `decompress` to ensure that it does not over-allocate if
129 /// you supply a large `capacity`.
130 ///
131 /// Will return `None` if the upper bound cannot be determined or is larger than `usize::MAX`
132 ///
133 /// Note that unless the `experimental` feature is enabled, this will always return `None`.
134 pub fn upper_boundrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'a>`]upper_bound().(_data: &[u8]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> {
135 #[cfg(feature = "experimental")]
136 {
137 let bound = zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::decompress_boundrust-analyzer cargo zstd-safe 7.2.2 decompress_bound().(_data).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
138 bound.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()
139 }
140 #[cfg(not(feature = "experimental"))]
141 {
142 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
143 }
144 }
145 }
146
147 fn _assert_traitsrust-analyzer cargo zstd 0.13.3 bulk/decompressor/_assert_traits().() {
148 fn _assert_sendrust-analyzer cargo zstd 0.13.3 bulk/decompressor/_assert_send().<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>(_: T) {}
149
150 _assert_sendrust-analyzer cargo zstd 0.13.3 bulk/decompressor/_assert_send().(Decompressorrust-analyzer cargo zstd 0.13.3 bulk/decompressor/Decompressor#::newrust-analyzer cargo zstd 0.13.3 bulk/decompressor/impl#[`Decompressor<'static>`]new().());
151 }