os_bridge/common/
core.rs

1extern crate walkdir;
2extern crate zip;
3
4use std::{fs::File, path::Path};
5use zip::ZipWriter;
6
7use crate::BridgeResult;
8
9/// OsBridge
10pub trait OsBridge {
11  fn get_pid(&self) -> BridgeResult<u32>;
12}
13
14/// zip
15pub trait Zip {
16  ///  Calculate file size
17  fn calculate_size<P>(&self, path: P) -> BridgeResult<f64>
18  where
19    P: AsRef<Path>;
20
21  /// Read file size
22  fn get_size<P>(&self, path: P) -> u64
23  where
24    P: AsRef<Path>;
25
26  /// @description:  Decompression extractor
27  /// @parama zip_src_path: Decompression target path
28  /// @parama zip_output_path: Output Path
29  fn extract<P>(&self, zip_src_path: P, zip_output_path: P) -> BridgeResult<bool>
30  where
31    P: AsRef<Path>;
32
33  /// @description:  Single file compression
34  /// @parama zip_input_path: Compression target path
35  /// @parama zip_output_path: Output Path
36  fn file_compression<P>(&self, zip_input_path: P, zip_output_path: P) -> BridgeResult<bool>
37  where
38    P: AsRef<Path>;
39
40  /// @description:  Single folder compression
41  /// @parama zip_input_path: Compression target path
42  /// @parama zip_output_path: Output Path
43  fn single_folder_compression<P>(
44    &self,
45    zip_input_path: P,
46    zip_output_path: P,
47  ) -> BridgeResult<bool>
48  where
49    P: AsRef<Path>;
50
51  /// @description:  Add directory
52  /// @parama zip_writer: ZipWriter
53  /// @parama base_dir: Directory path
54  /// @parama current_dir: Base directory
55  fn add_dir<P>(
56    &self,
57    zip_writer: &mut ZipWriter<File>,
58    base_dir: P,
59    current_dir: P,
60  ) -> BridgeResult<bool>
61  where
62    P: AsRef<Path>;
63
64  /// batch compression
65  /// Please provide a list path
66  /// @parama zip_input_paths: [zip_input_path1, zip_input_path2, ...]
67  /// @parama zip_output_path: Output Path
68  fn batch_compression<P>(&self, zip_input_paths: Vec<P>, zip_output_path: P) -> BridgeResult<bool>
69  where
70    P: AsRef<Path>;
71
72  /// @description Check whether the folder is empty
73  /// @parama path: Path
74  fn check_folder_is_empty<P>(&self, path: P) -> BridgeResult<bool>
75  where
76    P: AsRef<Path>;
77
78  /// @description: Add a path to the zip file
79  /// @parama zip_writer: zip_writer
80  /// @parama path: Path
81  fn add_path<P>(&self, zip_writer: &mut ZipWriter<File>, path: P) -> BridgeResult<bool>
82  where
83    P: AsRef<Path>;
84}