escnul – NUL-safe byte escaping for embedding in shell scripts
no_std support
escnul supports no_std with alloc.
- default features:
std no_stdbuild: disable default features
[]
= { = "0.2", = false }
The core escaping APIs work in no_std + alloc.
EncodeDecodeOnePassEscapeEngineTwoPassEscapeEngineShellDecodeMode::decoder_fragmentTrSedEngine
The stream-oriented APIs require std and are only available with the std feature.
StreamEncodeErrorTwoPassEscapeEngine::choose_shell_decode_mode_readerShellDecodeMode::encode_reader
Overview
- [
escape] module provides a low-overhead, reversible byte-escaping scheme for transforming arbitrary binary data into a stream that can be safely embedded in a Bourne-shell script and decoded later with onlytr+sed(or via the provided Rust APIs). - [
OnePassEscapeEngine] performs a single-pass encode/decode using a user-chosen escape byte. - [
TwoPassEscapeEngine] scans your data first, then either copies it raw (if no NULs) or picks a rare escape byte and delegates to [OnePassEscapeEngine]. - [
ShellDecodeMode] exposes the low-level shell decode plan used for embedding payloads into POSIX shell scripts. - [
ShellDecodeMode::encode_reader] supports streamingRead -> Writeencoding without buffering the whole payload in memory. - All engines implement the [
Encode], [Decode], and [Engine] traits for zero-allocation streaming into pre-allocated buffers.
Example
use ;
// 1-pass encode/decode with user-chosen escape '@'
let data = b"hello\0world";
let mut buf = vec!;
let m = new.encode_slice.unwrap;
assert_eq!;
// 2-pass engine: chooses raw copy if no NUL, else escapes
let engine = TWO_PASS_SED;
let enc = engine.encode;
assert_eq!;
let dec = engine.decode;
assert_eq!;
Shell-oriented usage:
use ;
let data = b"hello\0world";
let mode = TWO_PASS_SED.choose_shell_decode_mode;
assert!;
let fragment = mode.decoder_fragment;
assert!;