Skip to content

Commit 82dc789

Browse files
committed
refactor!: remove usage of Box<PathBuf>
BREAKING CHANGE: the parameter is changed on public methods.
1 parent f378ded commit 82dc789

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/chunk.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use bytes::Bytes;
1111
use rayon::prelude::*;
1212
use xor_name::XorName;
1313

14-
///
1514
#[derive(Clone)]
1615
pub(crate) struct EncryptionBatch {
1716
pub(crate) raw_chunks: Vec<RawChunk>,

src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub struct EncryptedChunk {
148148
#[derive(Clone)]
149149
pub struct StreamSelfEncryptor {
150150
// File path for the encryption target.
151-
file_path: Box<PathBuf>,
151+
file_path: PathBuf,
152152
// List of `(start_position, end_position)` for each chunk for the target file.
153153
batch_positions: Vec<(usize, usize)>,
154154
// Current step (i.e. chunk_index) for encryption
@@ -158,15 +158,15 @@ pub struct StreamSelfEncryptor {
158158
// Progressing collection of source chunks' names
159159
src_hashes: BTreeMap<usize, XorName>,
160160
// File path to flush encrypted_chunks into.
161-
chunk_dir: Option<Box<PathBuf>>,
161+
chunk_dir: Option<PathBuf>,
162162
}
163163

164164
impl StreamSelfEncryptor {
165165
/// For encryption, return with an intialized streaming encryptor.
166166
/// If a `chunk_dir` is provided, the encrypted_chunks will be written into the specified dir as well.
167167
pub fn encrypt_from_file(
168-
file_path: Box<PathBuf>,
169-
chunk_dir: Option<Box<PathBuf>>,
168+
file_path: PathBuf,
169+
chunk_dir: Option<PathBuf>,
170170
) -> Result<Self> {
171171
let file = File::open(&*file_path)?;
172172
let metadata = file.metadata()?;
@@ -261,7 +261,7 @@ impl StreamSelfEncryptor {
261261
/// The streaming decryptor to carry out the decryption on fly, chunk by chunk.
262262
pub struct StreamSelfDecryptor {
263263
// File path for the decryption output.
264-
file_path: Box<PathBuf>,
264+
file_path: PathBuf,
265265
// Current step (i.e. chunk_index) for decryption
266266
chunk_index: usize,
267267
// Source hashes of the chunks that collected from the data_map, they shall already be sorted by index.
@@ -274,7 +274,7 @@ pub struct StreamSelfDecryptor {
274274

275275
impl StreamSelfDecryptor {
276276
/// For decryption, return with an intialized streaming decryptor
277-
pub fn decrypt_to_file(file_path: Box<PathBuf>, data_map: &DataMap) -> Result<Self> {
277+
pub fn decrypt_to_file(file_path: PathBuf, data_map: &DataMap) -> Result<Self> {
278278
let temp_dir = tempdir()?;
279279
let src_hashes = extract_hashes(data_map);
280280

src/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ fn test_stream_self_encryptor() -> Result<(), Error> {
3535

3636
// Encrypt the file using StreamSelfEncryptor
3737
let mut encryptor = StreamSelfEncryptor::encrypt_from_file(
38-
Box::new(file_path),
39-
Some(Box::new(chunk_path.clone())),
38+
file_path,
39+
Some(chunk_path.clone()),
4040
)?;
4141
let mut encrypted_chunks = Vec::new();
4242
let mut data_map = None;
@@ -68,7 +68,7 @@ fn test_stream_self_encryptor() -> Result<(), Error> {
6868
}
6969

7070
let mut decryptor =
71-
StreamSelfDecryptor::decrypt_to_file(Box::new(decrypted_file_path.clone()), &data_map)?;
71+
StreamSelfDecryptor::decrypt_to_file(decrypted_file_path.clone(), &data_map)?;
7272
for chunk in encrypted_chunks {
7373
let _ = decryptor.next_encrypted(chunk)?;
7474
}

0 commit comments

Comments
 (0)