1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//! Compression functions for the .zeck file format
use crateZeckFormatError;
use crateZeckFile;
use crate::;
use ;
use TryFrom;
use Tsify;
use *;
/// Result of best compression attempt, containing the best compressed zeck file and the size for the other endianness attempt, or if neither produced compression (both were larger than the original).
/// Compresses data using the Zeckendorf algorithm with automatic endianness selection,
/// and stores the result in a [`BestCompressionResult`] struct.
///
/// This function attempts compression with both big endian and little endian interpretations,
/// and returns the best result, or if neither produced compression (both were larger than the original).
///
/// # ⚠️ Warning
///
/// **Compressing or decompressing data larger than 10KB (10,000 bytes) is unstable due to time and memory pressure.**
/// The library may experience performance issues, excessive memory usage, or failures when processing data exceeding this size.
///
/// # Examples
///
/// ```
/// # use zeck::zeck_file_format::compress::compress_zeck_best;
/// # use zeck::zeck_file_format::compress::BestCompressionResult;
/// # use zeck::zeck_file_format::decompress::decompress_zeck_file;
/// let data = vec![0, 1]; // Compresses best interpreted as a big endian integer
/// match compress_zeck_best(&data) {
/// Ok(best_compression_result) => {
/// match best_compression_result {
/// BestCompressionResult::BigEndianBest { zeck_file, le_size } => {
/// let decompressed = decompress_zeck_file(&zeck_file).unwrap();
/// assert_eq!(decompressed, data);
/// }
/// BestCompressionResult::LittleEndianBest { zeck_file, be_size } => {
/// assert!(false);
/// }
/// BestCompressionResult::Neither { be_size, le_size } => {
/// assert!(false);
/// }
/// }
/// }
/// Err(e) => {
/// assert!(false);
/// }
/// }
///
/// let data = vec![1, 0]; // Compresses best interpreted as a little endian integer
/// match compress_zeck_best(&data) {
/// Ok(best_compression_result) => {
/// match best_compression_result {
/// BestCompressionResult::BigEndianBest { zeck_file, le_size } => {
/// assert!(false);
/// }
/// BestCompressionResult::LittleEndianBest { zeck_file, be_size } => {
/// let decompressed = decompress_zeck_file(&zeck_file).unwrap();
/// assert_eq!(decompressed, data);
/// }
/// BestCompressionResult::Neither { be_size, le_size } => {
/// assert!(false);
/// }
/// }
/// }
/// Err(e) => {
/// assert!(false);
/// }
/// }
/// ```
/// Compresses data using the Zeckendorf algorithm with little endian interpretation,
/// and stores the result in a [`ZeckFile`] struct.
///
/// # ⚠️ Warning
///
/// **Compressing or decompressing data larger than 10KB (10,000 bytes) is unstable due to time and memory pressure.**
/// The library may experience performance issues, excessive memory usage, or failures when processing data exceeding this size.
///
/// # Examples
///
/// ```
/// # use zeck::zeck_file_format::compress::compress_zeck_le;
/// let data = vec![1, 0];
/// match compress_zeck_le(&data) {
/// Ok(zeck_file) => {
/// // Access file information
/// println!("Original size: {} bytes", zeck_file.original_size);
/// println!("Compressed size: {} bytes", zeck_file.compressed_data.len());
/// // Serialize to bytes for writing to file
/// let bytes = zeck_file.to_bytes();
/// }
/// Err(e) => {
/// // Handle error (e.g., data size too large)
/// }
/// }
/// ```
/// Compresses data using the Zeckendorf algorithm with big endian interpretation,
/// and stores the result in a [`ZeckFile`] struct.
///
/// # ⚠️ Warning
///
/// **Compressing or decompressing data larger than 10KB (10,000 bytes) is unstable due to time and memory pressure.**
/// The library may experience performance issues, excessive memory usage, or failures when processing data exceeding this size.
///
/// # Examples
///
/// ```
/// # use zeck::zeck_file_format::compress::compress_zeck_be;
/// let data = vec![1, 0];
/// match compress_zeck_be(&data) {
/// Ok(zeck_file) => {
/// // Access file information
/// println!("Original size: {} bytes", zeck_file.original_size);
/// println!("Is big endian: {}", zeck_file.is_big_endian());
/// // Serialize to bytes for writing to file
/// let bytes = zeck_file.to_bytes();
/// }
/// Err(e) => {
/// // Handle error (e.g., data size too large)
/// }
/// }
/// ```