roxify 1.2.7 → 1.2.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.
- package/CHANGELOG.md +74 -0
- package/LICENSE +21 -21
- package/README.md +370 -117
- package/dist/cli.d.ts +2 -2
- package/dist/cli.js +607 -606
- package/dist/index.d.ts +13 -13
- package/dist/index.js +13 -13
- package/dist/minpng.d.ts +8 -8
- package/dist/minpng.js +238 -238
- package/dist/pack.d.ts +31 -31
- package/dist/pack.js +205 -188
- package/dist/roxify-cli +0 -0
- package/dist/utils/constants.d.ts +38 -38
- package/dist/utils/constants.js +22 -22
- package/dist/utils/crc.d.ts +4 -4
- package/dist/utils/crc.js +29 -29
- package/dist/utils/decoder.d.ts +4 -4
- package/dist/utils/decoder.js +665 -665
- package/dist/utils/encoder.d.ts +4 -4
- package/dist/utils/encoder.js +391 -422
- package/dist/utils/errors.d.ts +9 -9
- package/dist/utils/errors.js +18 -18
- package/dist/utils/helpers.d.ts +11 -11
- package/dist/utils/helpers.js +112 -76
- package/dist/utils/inspection.d.ts +19 -19
- package/dist/utils/inspection.js +518 -518
- package/dist/utils/optimization.d.ts +3 -3
- package/dist/utils/optimization.js +640 -640
- package/dist/utils/reconstitution.d.ts +3 -3
- package/dist/utils/reconstitution.js +266 -266
- package/dist/utils/rust-cli-wrapper.d.ts +1 -0
- package/dist/utils/rust-cli-wrapper.js +36 -0
- package/dist/utils/types.d.ts +46 -44
- package/dist/utils/types.js +1 -1
- package/dist/utils/zstd.d.ts +17 -17
- package/dist/utils/zstd.js +153 -131
- package/libroxify_native.node +0 -0
- package/package.json +48 -65
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [1.2.10] - 2026-01-09
|
|
4
|
+
|
|
5
|
+
### Performance 🚀🚀
|
|
6
|
+
|
|
7
|
+
- **MASSIVE file packing speedup**: 18,750 files (660MB) now in **7 seconds** (was 18s)
|
|
8
|
+
- Parallelized file reading with `fs.promises.readFile()` and `Promise.all()` batching
|
|
9
|
+
- Batch size optimized to 1000 files per parallel read
|
|
10
|
+
- Improved buffer concatenation strategy (array accumulation + single concat)
|
|
11
|
+
- Added error handling for unreadable files during parallel reads
|
|
12
|
+
|
|
13
|
+
### Benchmarks
|
|
14
|
+
|
|
15
|
+
- Single file 1GB: 389ms (2.63 GB/s)
|
|
16
|
+
- Directory 18,750 files (660MB): **6.8s** (97 MB/s including I/O overhead)
|
|
17
|
+
|
|
18
|
+
## [1.2.9] - 2026-01-09
|
|
19
|
+
|
|
20
|
+
### Performance 🚀
|
|
21
|
+
|
|
22
|
+
- **EXTREME SPEED**: 1GB encode in 0.39s (**2.6 GB/s throughput**)
|
|
23
|
+
- Optimized PNG pixel copying from byte-by-byte loops to bulk Buffer.copy() operations
|
|
24
|
+
- Reduced PNG deflate overhead by using zlib level 0 (data already compressed with Zstd)
|
|
25
|
+
- Lowered large image threshold from 50M to 10M pixels for faster manual PNG generation
|
|
26
|
+
- Default Zstd compression level changed from 15 to 3 (much faster, still excellent ratio)
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- Added `compressionLevel` option to `EncodeOptions` (default: 3)
|
|
31
|
+
- Added `skipOptimization` option to disable zopfli PNG optimization
|
|
32
|
+
- CLI now disables PNG optimization by default for maximum speed
|
|
33
|
+
|
|
34
|
+
### Benchmarks
|
|
35
|
+
|
|
36
|
+
- 1KB: 14.77ms
|
|
37
|
+
- 100MB: 63.74ms (1.57 GB/s)
|
|
38
|
+
- 500MB: 203ms (2.46 GB/s)
|
|
39
|
+
- 1GB: 389ms (2.63 GB/s)
|
|
40
|
+
|
|
41
|
+
## [1.2.8] - 2026-01-09
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
- 🦀 **Native Rust acceleration** via N-API for extreme performance
|
|
46
|
+
- Delta encoding/decoding with Rayon parallelization
|
|
47
|
+
- Multi-threaded Zstd compression (level 19) with `zstdmt` feature
|
|
48
|
+
- Fast CRC32 and Adler32 checksums
|
|
49
|
+
- Parallel pixel scanning for ROX1 magic and markers
|
|
50
|
+
- ⚡ **Performance improvements**: Up to 1GB/s throughput on modern hardware
|
|
51
|
+
- 1GB encode: ~1.2s (863 MB/s)
|
|
52
|
+
- 1GB decode: ~1.0s (1031 MB/s)
|
|
53
|
+
- 🔄 **Automatic fallback**: Pure TypeScript implementation when native module unavailable
|
|
54
|
+
- 📦 **Unified repository**: Rust and TypeScript code in single npm package
|
|
55
|
+
|
|
56
|
+
### Changed
|
|
57
|
+
|
|
58
|
+
- Switched from `@mongodb-js/zstd` to native Rust zstd for better performance
|
|
59
|
+
- Updated package description to highlight native acceleration
|
|
60
|
+
- Compression ratio improved to 0.01-0.05% with Zstd level 19
|
|
61
|
+
|
|
62
|
+
### Technical
|
|
63
|
+
|
|
64
|
+
- Added `build:native` and `build:all` npm scripts
|
|
65
|
+
- Native module compiled to `libroxify_native.node` (1.8MB)
|
|
66
|
+
- Cargo workspace configured with `native/` directory
|
|
67
|
+
- Updated dependencies: Rust crates (napi, rayon, zstd, crc32fast, adler)
|
|
68
|
+
|
|
69
|
+
## [1.0.4] - Previous release
|
|
70
|
+
|
|
71
|
+
- Initial TypeScript implementation
|
|
72
|
+
- Brotli compression
|
|
73
|
+
- Multiple encoding modes (compact, chunk, pixel, screenshot)
|
|
74
|
+
- AES-256-GCM encryption support
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 RoxCompressor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,117 +1,370 @@
|
|
|
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
|
-
|
|
1
|
+
# RoxCompressor Transform
|
|
2
|
+
|
|
3
|
+
> Encode binary data into PNG images and decode them back. Fast, efficient, with optional encryption and native Rust acceleration.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/roxify)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- ⚡ **Blazing Fast**: Native Rust acceleration via N-API — **1GB/s** throughput on modern hardware
|
|
11
|
+
- 🚀 **Optimized Compression**: Multi-threaded Zstd compression (level 19) with parallel processing
|
|
12
|
+
- 🔒 **Secure**: AES-256-GCM encryption support with PBKDF2 key derivation
|
|
13
|
+
- 🎨 **Multiple modes**: Compact, chunk, pixel, and screenshot modes
|
|
14
|
+
- 📦 **CLI & API**: Use as command-line tool or JavaScript library
|
|
15
|
+
- 🔄 **Lossless**: Perfect roundtrip encoding/decoding
|
|
16
|
+
- 📊 **Efficient**: Typically 0.01-0.05% of original size with Zstd compression
|
|
17
|
+
- 📖 **Full TSDoc**: Complete TypeScript documentation
|
|
18
|
+
- 🦀 **Rust Powered**: Optional native module for extreme performance (falls back to pure JS)
|
|
19
|
+
|
|
20
|
+
## Documentation
|
|
21
|
+
|
|
22
|
+
- 📘 **[CLI Documentation](./CLI.md)** - Complete command-line usage guide
|
|
23
|
+
- 📗 **[JavaScript SDK](./JAVASCRIPT_SDK.md)** - Programmatic API reference with examples
|
|
24
|
+
- 📙 **[Quick Start](#quick-start)** - Get started in 2 minutes
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
### As CLI tool (npx)
|
|
29
|
+
|
|
30
|
+
No installation needed! Use directly with npx:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npx rox encode input.zip output.png
|
|
34
|
+
npx rox decode output.png original.zip
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### As library
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install roxify
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## CLI Usage
|
|
44
|
+
|
|
45
|
+
### Quick Start
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Encode a file
|
|
49
|
+
npx rox encode document.pdf document.png
|
|
50
|
+
|
|
51
|
+
# Decode it back
|
|
52
|
+
npx rox decode document.png document.pdf
|
|
53
|
+
|
|
54
|
+
# With encryption
|
|
55
|
+
npx rox encode secret.zip secret.png -p mypassword
|
|
56
|
+
npx rox decode secret.png secret.zip -p mypassword
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### CLI Commands
|
|
60
|
+
|
|
61
|
+
#### `encode` - Encode file to PNG
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npx rox encode <input> [output] [options]
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Options:**
|
|
68
|
+
|
|
69
|
+
- `-p, --passphrase <pass>` - Encrypt with passphrase (AES-256-GCM)
|
|
70
|
+
- `-m, --mode <mode>` - Encoding mode: `compact|chunk|pixel|screenshot` (default: `screenshot`)
|
|
71
|
+
- `-q, --quality <0-11>` - Brotli compression quality (default: `1`)
|
|
72
|
+
- `0` = fastest, largest
|
|
73
|
+
- `11` = slowest, smallest
|
|
74
|
+
- `-e, --encrypt <type>` - Encryption: `auto|aes|xor|none` (default: `aes` if passphrase)
|
|
75
|
+
- `--no-compress` - Disable compression
|
|
76
|
+
- `-o, --output <path>` - Output file path
|
|
77
|
+
|
|
78
|
+
**Examples:**
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Basic encoding
|
|
82
|
+
npx rox encode data.bin output.png
|
|
83
|
+
|
|
84
|
+
# Fast compression for large files
|
|
85
|
+
npx rox encode large-video.mp4 output.png -q 0
|
|
86
|
+
|
|
87
|
+
# High compression for small files
|
|
88
|
+
npx rox encode config.json output.png -q 11
|
|
89
|
+
|
|
90
|
+
# With encryption
|
|
91
|
+
npx rox encode secret.pdf secure.png -p "my secure password"
|
|
92
|
+
|
|
93
|
+
# Compact mode (smallest PNG)
|
|
94
|
+
npx rox encode data.bin tiny.png -m compact
|
|
95
|
+
|
|
96
|
+
# Screenshot mode (recommended, looks like a real image)
|
|
97
|
+
npx rox encode archive.tar.gz screenshot.png -m screenshot
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### `decode` - Decode PNG to file
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
npx rox decode <input> [output] [options]
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**Options:**
|
|
107
|
+
|
|
108
|
+
- `-p, --passphrase <pass>` - Decryption passphrase
|
|
109
|
+
- `-o, --output <path>` - Output file path (auto-detected from metadata if not provided)
|
|
110
|
+
|
|
111
|
+
**Examples:**
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
# Basic decoding
|
|
115
|
+
npx rox decode encoded.png output.bin
|
|
116
|
+
|
|
117
|
+
# Auto-detect filename from metadata
|
|
118
|
+
npx rox decode encoded.png
|
|
119
|
+
|
|
120
|
+
# With decryption
|
|
121
|
+
npx rox decode encrypted.png output.pdf -p "my secure password"
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## JavaScript API
|
|
125
|
+
|
|
126
|
+
### Basic Usage
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import { encodeBinaryToPng, decodePngToBinary } from 'roxify';
|
|
130
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
131
|
+
|
|
132
|
+
// Encode
|
|
133
|
+
const input = readFileSync('input.zip');
|
|
134
|
+
const png = await encodeBinaryToPng(input, {
|
|
135
|
+
mode: 'screenshot',
|
|
136
|
+
name: 'input.zip',
|
|
137
|
+
});
|
|
138
|
+
writeFileSync('output.png', png);
|
|
139
|
+
|
|
140
|
+
// Decode
|
|
141
|
+
const encoded = readFileSync('output.png');
|
|
142
|
+
const result = await decodePngToBinary(encoded);
|
|
143
|
+
writeFileSync(result.meta?.name || 'output.bin', result.buf);
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### With Encryption
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
// Encode with AES-256-GCM
|
|
150
|
+
const png = await encodeBinaryToPng(input, {
|
|
151
|
+
mode: 'screenshot',
|
|
152
|
+
passphrase: 'my-secret-password',
|
|
153
|
+
encrypt: 'aes',
|
|
154
|
+
name: 'secret.zip',
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// Decode with passphrase
|
|
158
|
+
const result = await decodePngToBinary(encoded, {
|
|
159
|
+
passphrase: 'my-secret-password',
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Fast Compression
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
// Optimize for speed (recommended for large files)
|
|
167
|
+
const png = await encodeBinaryToPng(largeBuffer, {
|
|
168
|
+
mode: 'screenshot',
|
|
169
|
+
brQuality: 0, // Fastest
|
|
170
|
+
name: 'large-file.bin',
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// Optimize for size (recommended for small files)
|
|
174
|
+
const png = await encodeBinaryToPng(smallBuffer, {
|
|
175
|
+
mode: 'compact',
|
|
176
|
+
brQuality: 11, // Best compression
|
|
177
|
+
name: 'config.json',
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Encoding Modes
|
|
182
|
+
|
|
183
|
+
#### `screenshot` (Recommended)
|
|
184
|
+
|
|
185
|
+
Encodes data as RGB pixel values, optimized for screenshot-like appearance. Best balance of size and compatibility.
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
const png = await encodeBinaryToPng(data, { mode: 'screenshot' });
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
#### `compact` (Smallest)
|
|
192
|
+
|
|
193
|
+
Minimal 1x1 PNG with data in custom chunk. Fastest and smallest.
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
const png = await encodeBinaryToPng(data, { mode: 'compact' });
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
#### `pixel`
|
|
200
|
+
|
|
201
|
+
Encodes data as RGB pixel values without screenshot optimization.
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
const png = await encodeBinaryToPng(data, { mode: 'pixel' });
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
#### `chunk`
|
|
208
|
+
|
|
209
|
+
Standard PNG with data in custom rXDT chunk.
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
const png = await encodeBinaryToPng(data, { mode: 'chunk' });
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## API Reference
|
|
216
|
+
|
|
217
|
+
### `encodeBinaryToPng(input, options)`
|
|
218
|
+
|
|
219
|
+
Encodes binary data into a PNG image.
|
|
220
|
+
|
|
221
|
+
**Parameters:**
|
|
222
|
+
|
|
223
|
+
- `input: Buffer` - The binary data to encode
|
|
224
|
+
- `options?: EncodeOptions` - Encoding options
|
|
225
|
+
|
|
226
|
+
**Returns:** `Promise<Buffer>` - The encoded PNG
|
|
227
|
+
|
|
228
|
+
**Options:**
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
interface EncodeOptions {
|
|
232
|
+
// Compression algorithm ('br' = Brotli, 'none' = no compression)
|
|
233
|
+
compression?: 'br' | 'none';
|
|
234
|
+
|
|
235
|
+
// Passphrase for encryption
|
|
236
|
+
passphrase?: string;
|
|
237
|
+
|
|
238
|
+
// Original filename to embed
|
|
239
|
+
name?: string;
|
|
240
|
+
|
|
241
|
+
// Encoding mode
|
|
242
|
+
mode?: 'compact' | 'chunk' | 'pixel' | 'screenshot';
|
|
243
|
+
|
|
244
|
+
// Encryption method
|
|
245
|
+
encrypt?: 'auto' | 'aes' | 'xor' | 'none';
|
|
246
|
+
|
|
247
|
+
// Output format
|
|
248
|
+
output?: 'auto' | 'png' | 'rox';
|
|
249
|
+
|
|
250
|
+
// Include filename in metadata (default: true)
|
|
251
|
+
includeName?: boolean;
|
|
252
|
+
|
|
253
|
+
// Brotli quality 0-11 (default: 1)
|
|
254
|
+
brQuality?: number;
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### `decodePngToBinary(pngBuf, options)`
|
|
259
|
+
|
|
260
|
+
Decodes a PNG image back to binary data.
|
|
261
|
+
|
|
262
|
+
**Parameters:**
|
|
263
|
+
|
|
264
|
+
- `pngBuf: Buffer` - The PNG image to decode
|
|
265
|
+
- `options?: DecodeOptions` - Decoding options
|
|
266
|
+
|
|
267
|
+
**Returns:** `Promise<DecodeResult>` - The decoded data and metadata
|
|
268
|
+
|
|
269
|
+
**Options:**
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
interface DecodeOptions {
|
|
273
|
+
// Passphrase for decryption
|
|
274
|
+
passphrase?: string;
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
**Result:**
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
interface DecodeResult {
|
|
282
|
+
// Decoded binary data
|
|
283
|
+
buf: Buffer;
|
|
284
|
+
|
|
285
|
+
// Extracted metadata
|
|
286
|
+
meta?: {
|
|
287
|
+
// Original filename
|
|
288
|
+
name?: string;
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## Performance Tips
|
|
294
|
+
|
|
295
|
+
### For Large Files (>10 MB)
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
# Use quality 0 for fastest encoding
|
|
299
|
+
npx rox encode large.bin output.png -q 0
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
const png = await encodeBinaryToPng(largeFile, {
|
|
304
|
+
mode: 'screenshot',
|
|
305
|
+
brQuality: 0, // 10-20x faster than default
|
|
306
|
+
});
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### For Small Files (<1 MB)
|
|
310
|
+
|
|
311
|
+
```bash
|
|
312
|
+
# Use quality 11 for best compression
|
|
313
|
+
npx rox encode small.json output.png -q 11 -m compact
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
const png = await encodeBinaryToPng(smallFile, {
|
|
318
|
+
mode: 'compact',
|
|
319
|
+
brQuality: 11, // Best compression ratio
|
|
320
|
+
});
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### Benchmark Results
|
|
324
|
+
|
|
325
|
+
File: 3.8 MB binary
|
|
326
|
+
|
|
327
|
+
- **Quality 0**: ~500-800ms, output ~1.2 MB
|
|
328
|
+
- **Quality 1** (default): ~1-2s, output ~800 KB
|
|
329
|
+
- **Quality 5**: ~8-12s, output ~750 KB
|
|
330
|
+
- **Quality 11**: ~20-30s, output ~720 KB
|
|
331
|
+
|
|
332
|
+
## Error Handling
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
try {
|
|
336
|
+
const result = await decodePngToBinary(encoded, {
|
|
337
|
+
passphrase: 'wrong-password',
|
|
338
|
+
});
|
|
339
|
+
} catch (err) {
|
|
340
|
+
if (err.message.includes('Incorrect passphrase')) {
|
|
341
|
+
console.error('Wrong password!');
|
|
342
|
+
} else if (err.message.includes('Invalid ROX format')) {
|
|
343
|
+
console.error('Not a valid RoxCompressor PNG');
|
|
344
|
+
} else {
|
|
345
|
+
console.error('Decode failed:', err.message);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
## Security
|
|
351
|
+
|
|
352
|
+
- **AES-256-GCM**: Authenticated encryption with 100,000 PBKDF2 iterations
|
|
353
|
+
- **XOR cipher**: Simple obfuscation (not cryptographically secure)
|
|
354
|
+
- **No encryption**: Data is compressed but not encrypted
|
|
355
|
+
|
|
356
|
+
⚠️ **Warning**: Use strong passphrases for sensitive data. The `xor` encryption mode is not secure and should only be used for obfuscation.
|
|
357
|
+
|
|
358
|
+
## License
|
|
359
|
+
|
|
360
|
+
MIT © RoxCompressor
|
|
361
|
+
|
|
362
|
+
## Contributing
|
|
363
|
+
|
|
364
|
+
Contributions welcome! Please open an issue or PR on GitHub.
|
|
365
|
+
|
|
366
|
+
## Links
|
|
367
|
+
|
|
368
|
+
- [GitHub Repository](https://github.com/RoxasYTB/RoxCompressor)
|
|
369
|
+
- [npm Package](https://www.npmjs.com/package/roxify)
|
|
370
|
+
- [Report Issues](https://github.com/RoxasYTB/RoxCompressor/issues)
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
export {};
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export {};
|