ctrl-z 0.1.0

A composable reader to treat `0x1A` as an end-of-file marker.
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented3 out of 3 items with examples
  • Size
  • Source code size: 25.46 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.5 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Anders429/ctrl-z
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Anders429

ctrl-z

GitHub Workflow Status codecov.io crates.io docs.rs MSRV License

A composable reader to treat 0x1A as an end-of-file marker.

Historically, 0x1A (commonly referred to as CTRL-Z, ^Z, or a "substitute character") was used in old systems to explicitly mark the end of a file. While modern systems no longer require this practice, some legacy files still contain this byte to mark the end of a file. This library provides a reader to treat 0x1A as the end of a file, rather than reading it as a regular byte.

Usage

This library provides a reader in the form of a struct named ReadToCtrlZ. As is common practice, this reader is composable with other types implementing the Read or BufRead traits. The reader checks the returned bytes for the presence of the EOF marker 0x1A and stops reading when it is encountered.

Example

For example, the reader defined below only reads until the 0x1A byte, at which point it stops reading.

use ctrl_z::ReadToCtrlZ;

let mut reader = ReadToCtrlZ::new(b"foo\x1abar".as_slice());
let mut output = String::new();

// Reading omits the final `0x1A` byte.
assert!(reader.read_to_string(&mut output).is_ok());
assert_eq!(output, "foo");

Minimum Supported Rust Version

This crate is guaranteed to compile on stable rustc 1.0.0 and up.

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.