roxify 1.13.7 → 1.13.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/cli.js +1 -8
  2. package/dist/stub-progress.d.ts +4 -4
  3. package/dist/stub-progress.js +4 -4
  4. package/dist/utils/decoder.d.ts +46 -2
  5. package/dist/utils/decoder.js +248 -38
  6. package/dist/utils/ecc.js +0 -1
  7. package/dist/utils/encoder.d.ts +30 -1
  8. package/dist/utils/encoder.js +34 -18
  9. package/dist/utils/inspection.d.ts +1 -1
  10. package/dist/utils/inspection.js +2 -2
  11. package/dist/utils/robust-audio.js +0 -13
  12. package/dist/utils/robust-image.js +0 -26
  13. package/package.json +12 -29
  14. package/roxify_native-aarch64-apple-darwin.node +0 -0
  15. package/roxify_native-aarch64-pc-windows-msvc.node +0 -0
  16. package/roxify_native-aarch64-unknown-linux-gnu.node +0 -0
  17. package/roxify_native-i686-pc-windows-msvc.node +0 -0
  18. package/roxify_native-i686-unknown-linux-gnu.node +0 -0
  19. package/{dist/rox-macos-universal → roxify_native-universal-apple-darwin.node} +0 -0
  20. package/roxify_native-x86_64-apple-darwin.node +0 -0
  21. package/roxify_native-x86_64-pc-windows-msvc.node +0 -0
  22. package/roxify_native-x86_64-unknown-linux-gnu.node +0 -0
  23. package/scripts/postinstall.cjs +23 -2
  24. package/Cargo.toml +0 -91
  25. package/dist/roxify_native +0 -0
  26. package/dist/roxify_native-macos-arm64 +0 -0
  27. package/dist/roxify_native-macos-x64 +0 -0
  28. package/dist/roxify_native.exe +0 -0
  29. package/native/archive.rs +0 -220
  30. package/native/audio.rs +0 -151
  31. package/native/bench_hybrid.rs +0 -145
  32. package/native/bwt.rs +0 -56
  33. package/native/context_mixing.rs +0 -117
  34. package/native/core.rs +0 -378
  35. package/native/crypto.rs +0 -209
  36. package/native/encoder.rs +0 -405
  37. package/native/hybrid.rs +0 -297
  38. package/native/image_utils.rs +0 -82
  39. package/native/io_advice.rs +0 -43
  40. package/native/io_ntfs_optimized.rs +0 -99
  41. package/native/lib.rs +0 -480
  42. package/native/main.rs +0 -842
  43. package/native/mtf.rs +0 -106
  44. package/native/packer.rs +0 -604
  45. package/native/png_chunk_writer.rs +0 -146
  46. package/native/png_utils.rs +0 -554
  47. package/native/pool.rs +0 -101
  48. package/native/progress.rs +0 -142
  49. package/native/rans.rs +0 -149
  50. package/native/rans_byte.rs +0 -286
  51. package/native/reconstitution.rs +0 -623
  52. package/native/streaming.rs +0 -189
  53. package/native/streaming_decode.rs +0 -625
  54. package/native/streaming_encode.rs +0 -684
  55. package/native/test_small_bwt.rs +0 -31
  56. package/native/test_stages.rs +0 -70
@@ -1,189 +0,0 @@
1
- use std::io::{Write, BufWriter};
2
- use std::fs::File;
3
- use std::path::Path;
4
-
5
- use crate::png_chunk_writer::{ChunkedIdatWriter, write_png_chunk};
6
-
7
- const PNG_HEADER: &[u8] = &[137, 80, 78, 71, 13, 10, 26, 10];
8
- const PIXEL_MAGIC: &[u8] = b"PXL1";
9
- const MARKER_START: [(u8, u8, u8); 3] = [(255, 0, 0), (0, 255, 0), (0, 0, 255)];
10
- const MARKER_END: [(u8, u8, u8); 3] = [(0, 0, 255), (0, 255, 0), (255, 0, 0)];
11
- const MARKER_ZSTD: (u8, u8, u8) = (0, 255, 0);
12
- const MAGIC: &[u8] = b"ROX1";
13
- const HEADER_VERSION_V2: u8 = 2;
14
-
15
- pub fn encode_to_png_file(
16
- data: &[u8],
17
- output_path: &Path,
18
- compression_level: i32,
19
- passphrase: Option<&str>,
20
- encrypt_type: Option<&str>,
21
- name: Option<&str>,
22
- file_list: Option<&str>,
23
- dict: Option<&[u8]>,
24
- ) -> anyhow::Result<()> {
25
- let compressed = crate::core::zstd_compress_with_prefix(data, compression_level, dict, MAGIC)
26
- .map_err(|e| anyhow::anyhow!("Compression failed: {}", e))?;
27
-
28
- let encrypted = if let Some(pass) = passphrase {
29
- match encrypt_type.unwrap_or("aes") {
30
- "xor" => crate::crypto::encrypt_xor(&compressed, pass),
31
- "aes" => crate::crypto::encrypt_aes(&compressed, pass)?,
32
- _ => crate::crypto::encrypt_aes(&compressed, pass)?,
33
- }
34
- } else {
35
- crate::crypto::no_encryption(&compressed)
36
- };
37
- drop(compressed);
38
-
39
- let meta_pixel = build_meta_pixel(&encrypted, name, file_list)?;
40
- drop(encrypted);
41
-
42
- let raw_payload_len = PIXEL_MAGIC.len() + meta_pixel.len();
43
- let padding_needed = (3 - (raw_payload_len % 3)) % 3;
44
- let padded_len = raw_payload_len + padding_needed;
45
-
46
- let marker_start_len = 12;
47
- let marker_end_bytes = 9;
48
- let data_with_markers_len = marker_start_len + padded_len;
49
- let data_pixels = (data_with_markers_len + 2) / 3;
50
- let end_marker_pixels = 3;
51
- let total_pixels = data_pixels + end_marker_pixels;
52
-
53
- let side = (total_pixels as f64).sqrt().ceil() as usize;
54
- let side = side.max(end_marker_pixels);
55
- let width = side;
56
- let height = side;
57
- let row_bytes = width * 3;
58
- let total_data_bytes = width * height * 3;
59
- let marker_end_pos = total_data_bytes - marker_end_bytes;
60
-
61
- let flat = build_flat_buffer(&meta_pixel, marker_end_pos, total_data_bytes);
62
- drop(meta_pixel);
63
-
64
- let stride = row_bytes + 1;
65
- let scanlines_total = height * stride;
66
-
67
- let mut scanlines = vec![0u8; scanlines_total];
68
- for row in 0..height {
69
- let flat_start = row * row_bytes;
70
- let flat_end = (flat_start + row_bytes).min(flat.len());
71
- let copy_len = flat_end.saturating_sub(flat_start);
72
- if copy_len > 0 {
73
- let dst = row * stride + 1;
74
- scanlines[dst..dst + copy_len].copy_from_slice(&flat[flat_start..flat_end]);
75
- }
76
- }
77
- drop(flat);
78
-
79
- let adler = crate::core::adler32_bytes(&scanlines);
80
-
81
- let f = File::create(output_path)?;
82
- let mut w = BufWriter::with_capacity(16 * 1024 * 1024, f);
83
-
84
- w.write_all(PNG_HEADER)?;
85
-
86
- let mut ihdr = [0u8; 13];
87
- ihdr[0..4].copy_from_slice(&(width as u32).to_be_bytes());
88
- ihdr[4..8].copy_from_slice(&(height as u32).to_be_bytes());
89
- ihdr[8] = 8;
90
- ihdr[9] = 2;
91
- write_png_chunk(&mut w, b"IHDR", &ihdr)?;
92
-
93
- write_idat_direct(&mut w, &scanlines, adler)?;
94
- drop(scanlines);
95
-
96
- if let Some(fl) = file_list {
97
- write_png_chunk(&mut w, b"rXFL", fl.as_bytes())?;
98
- }
99
- write_png_chunk(&mut w, b"IEND", &[])?;
100
- w.flush()?;
101
-
102
- Ok(())
103
- }
104
-
105
- fn write_idat_direct<W: Write>(
106
- w: &mut W,
107
- scanlines: &[u8],
108
- adler: u32,
109
- ) -> anyhow::Result<()> {
110
- const MAX_BLOCK: usize = 65535;
111
-
112
- let mut idat = ChunkedIdatWriter::new(w);
113
-
114
- let zlib = [0x78u8, 0x01];
115
- idat.write_all(&zlib)?;
116
-
117
- let mut offset = 0;
118
- while offset < scanlines.len() {
119
- let chunk_size = (scanlines.len() - offset).min(MAX_BLOCK);
120
- let is_last = offset + chunk_size >= scanlines.len();
121
- let header = [
122
- if is_last { 0x01 } else { 0x00 },
123
- chunk_size as u8,
124
- (chunk_size >> 8) as u8,
125
- !chunk_size as u8,
126
- (!(chunk_size >> 8)) as u8,
127
- ];
128
- idat.write_all(&header)?;
129
- let slice = &scanlines[offset..offset + chunk_size];
130
- idat.write_all(slice)?;
131
- offset += chunk_size;
132
- }
133
-
134
- let adler_bytes = adler.to_be_bytes();
135
- idat.write_all(&adler_bytes)?;
136
- idat.finish()
137
- }
138
-
139
- fn build_flat_buffer(
140
- meta_pixel: &[u8],
141
- marker_end_pos: usize,
142
- total_data_bytes: usize,
143
- ) -> Vec<u8> {
144
- let mut flat = vec![0u8; total_data_bytes];
145
-
146
- let mut pos = 0;
147
- for m in &MARKER_START {
148
- flat[pos] = m.0; flat[pos + 1] = m.1; flat[pos + 2] = m.2;
149
- pos += 3;
150
- }
151
- flat[pos] = MARKER_ZSTD.0; flat[pos + 1] = MARKER_ZSTD.1; flat[pos + 2] = MARKER_ZSTD.2;
152
- pos += 3;
153
- flat[pos..pos + PIXEL_MAGIC.len()].copy_from_slice(PIXEL_MAGIC);
154
- pos += PIXEL_MAGIC.len();
155
- flat[pos..pos + meta_pixel.len()].copy_from_slice(meta_pixel);
156
-
157
- for (i, m) in MARKER_END.iter().enumerate() {
158
- let off = marker_end_pos + i * 3;
159
- flat[off] = m.0; flat[off + 1] = m.1; flat[off + 2] = m.2;
160
- }
161
-
162
- flat
163
- }
164
-
165
- fn build_meta_pixel(payload: &[u8], name: Option<&str>, file_list: Option<&str>) -> anyhow::Result<Vec<u8>> {
166
- let version = HEADER_VERSION_V2;
167
- let name_bytes = name.map(|n| n.as_bytes()).unwrap_or(&[]);
168
- let name_len = name_bytes.len().min(255) as u8;
169
- let payload_len_bytes = (payload.len() as u64).to_be_bytes();
170
-
171
- let mut result = Vec::with_capacity(1 + 1 + name_len as usize + 8 + payload.len() + 256);
172
- result.push(version);
173
- result.push(name_len);
174
- if name_len > 0 {
175
- result.extend_from_slice(&name_bytes[..name_len as usize]);
176
- }
177
- result.extend_from_slice(&payload_len_bytes);
178
- result.extend_from_slice(payload);
179
-
180
- if let Some(fl) = file_list {
181
- result.extend_from_slice(b"rXFL");
182
- let json_bytes = fl.as_bytes();
183
- result.extend_from_slice(&(json_bytes.len() as u32).to_be_bytes());
184
- result.extend_from_slice(json_bytes);
185
- }
186
-
187
- Ok(result)
188
- }
189
-