Rust crate for making Read streams peekable.

Related tags

Utilities peekread
Overview

peekread

This crate allows you to take an arbitrary Read stream and 'peek ahead' into the stream without consuming the original stream. This is done through the PeekRead trait which has the method peek. When this method is called it returns a new PeekCursor object implementing Read, BufRead and Seek that allows you to read from the stream without affecting the original stream. The PeekRead trait is directly implemented on a select few types, but for most you will have to wrap your type in a SeekPeekReader or BufPeekReader that implements the peeking behavior using respectively seeking or buffering. Please refer to the the documentation for more information.

The minimum required stable Rust version for peekread is 1.31.0. To start using peekread add the following to your Cargo.toml:

[dependencies]
peekread = "0.1"

Example

A short example:

use peekread::{PeekRead, SeekPeekReader};

let mut f = SeekPeekReader::new(File::open("ambiguous")?);

// HTML is so permissive its parser never fails, so check for signature.
if f.starts_with(") {
    Ok(ParseResult::Html(parse_as_html(f)))
} else {
    // Can pass PeekCursor to functions accepting T: Read without them
    // having to be aware of peekread.
    parse_as_jpg(f.peek()).map(ParseResult::Jpg)
       .or_else(|_| parse_as_png(f.peek()).map(ParseResult::Png))
       .or_else(|_| parse_as_gif(f.peek()).map(ParseResult::Gif))
       .or_else(|_| parse_as_javascript(f.peek()).map(ParseResult::Js))
}

License

peekread is released under the Zlib license, a permissive license. It is OSI and FSF approved and GPL compatible.

You might also like...
Rust crate for reading SER files used in astrophotography

Rust crate for reading SER files used in astrophotography.

A Rust crate for handling URNs.

URN A Rust crate for handling URNs. Parsing and comparison is done according to the spec (meaning only part of the URN is used for equality checks). S

The efficient and elegant crate to count variants of Rust's Enum.

variant-counter The efficient and elegant crate to count variants of Rust's Enum. Get started #[derive(VariantCount)] #[derive(VariantCount)] pub enum

This crate allows you to safely initialize Dynamically Sized Types (DST) using only safe Rust.

This crate allows you to safely initialize Dynamically Sized Types (DST) using only safe Rust.

An experimental Rust crate for sigstore

Continuous integration Docs License This is an experimental crate to interact with sigstore. This is under high development, many features and checks

Rust crate that provides a convenient macro to quickly plot variables.
Rust crate that provides a convenient macro to quickly plot variables.

Debug Plotter This crate provides a convenient macro to quickly plot variables. Documentation For more information on how to use this crate, please ta

Rust Hardware Abstraction Layer (HAL) crate for the Vorago VA108xx family of MCUs

HAL for the Vorago VA108xx MCU family This repository contains the Hardware Abstraction Layer (HAL), which is an additional hardware abstraction on to

IDX is a Rust crate for working with RuneScape .idx-format caches.
IDX is a Rust crate for working with RuneScape .idx-format caches.

This image proudly made in GIMP License Licensed under GNU GPL, Version 3.0, (LICENSE-GPL3 or https://choosealicense.com/licenses/gpl-3.0/) Contributi

Board Support Crate for Arduino Leonardo in Rust

Deprecation Note: This crate will soon be deprecated in favor of avr-hal. avr-hal is a new approach to writing the HAL crate, that was designed with s

Owner
Orson Peters
Orson Peters
A Rust utility library, making easier by taking the hassle out of working. :octocat:

reddish A Rust utility library, making easier by taking the hassle out of working. Usage Add this to your Cargo.toml: [dependencies] reddish = "0.2.0"

Rogério Araújo 12 Jan 21, 2023
🦸‍♂️ Recast migrates your old extensions to AndroidX, making them compatible with the latest version of Kodular.

Recast Recast helps make your old extensions compatible with Kodular Creator version 1.5.0 or above. Prerequisites To use Recast, you need to have Jav

Shreyash Saitwal 13 Dec 28, 2022
A simple wrapper for the detour-rs library that makes making hooks much more concise

A simple wrapper for the detour-rs library that makes making hooks much more concise

Khangaroo 6 Jun 21, 2022
Tool written in rust to read for file changes and accordingly run build commands.

Sniff A simple tool written in rust to read for file changes and accordingly run build commands. Note this tool is for linux and linux only. If it hap

Aakash Sen Sharma 4 Oct 2, 2022
Rust crate which provides direct access to files within a Debian archive

debarchive This Rust crate provides direct access to files within a Debian archive. This crate is used by our debrep utility to generate the Packages

Pop!_OS 11 Dec 18, 2021
Granular locking crate for Rust

Granular locking crate for Rust. Instead of using coarse-grained Mutex or RwLock which can be used to lock an entire structure, glock provides more granular locking.

Ayman Madkour 9 Jul 22, 2022
A crate to implement leader election for Kubernetes workloads in Rust.

Kubernetes Leader Election in Rust This library provides simple leader election for Kubernetes workloads.

Hendrik Maus 33 Dec 29, 2022
This crate allows writing a struct in Rust and have it derive a struct of arrays layed out in memory according to the arrow format.

Arrow2-derive - derive for Arrow2 This crate allows writing a struct in Rust and have it derive a struct of arrays layed out in memory according to th

Jorge Leitao 29 Dec 27, 2022
Tiny Rust crate to iterate bit combinations

bit_combi_iter bit_combi_iter is a small dependency-free crate to enumerate all bit combinations less than given unsigned integer value keeping 1s in

Linda_pp 5 Apr 11, 2022
Membrane is an opinionated crate that generates a Dart package from a Rust library. Extremely fast performance with strict typing and zero copy returns over the FFI boundary via bincode.

Membrane is an opinionated crate that generates a Dart package from a Rust library. Extremely fast performance with strict typing and zero copy returns over the FFI boundary via bincode.

Jerel Unruh 70 Dec 13, 2022