pub fn encode_stream<R: Read, W: Write>(
reader: &mut R,
writer: &mut W,
) -> Result<()>Expand description
Encodes a byte stream into a string representation using a defined emoji map.
This function is designed to convert bytes into a specific set of emoji characters, providing a fun and unique way of representing data.
It accepts any type that implements Read (for reading bytes)
and Write (for writing the resulting emojis),
and returns a Result<(), io::Error>. Each input byte is mapped
to a specific emoji character, with the help of two maps: EMOJI_MAP and TAIL_MAP.
§Arguments
reader- An object implementingReadto read bytes from.writer- An object implementingWriteto write emojis to.
§Returns
An io::Result<()>. If it is Err, an error occurred while reading or writing.
§Panics
This function will panic if any emoji character needed for encoding is not
present in EMOJI_MAP or TAIL_MAP. This is not expected to ever happen.
§Example
use mojibake::encode_stream;
use std::io::Cursor;
let input = vec![0x31, 0x32, 0x33];
let mut reader = Cursor::new(input);
let mut writer = Cursor::new(Vec::new());
encode_stream(&mut reader, &mut writer).expect("encoding failed");
println!("{}", String::from_utf8(writer.into_inner()).unwrap());