Skip to main content

Module parse

Module parse 

Source
Expand description

Sans-IO tar archive parser.

This module provides a sans-IO state machine parser for tar archives. It operates on &[u8] slices directly (no Read trait bound), making it suitable for:

  • Async I/O (tokio, async-std)
  • Custom buffering strategies
  • Zero-copy parsing in memory-mapped archives
  • Embedding in other parsers

In addition to the parser itself, this module contains the configuration and error types it uses: Limits for security limits and ParseError for error reporting.

§Design

The parser is a state machine that processes bytes and emits ParseEvents. The caller is responsible for:

  1. Providing input data via Parser::parse
  2. Handling events (headers, content markers, end-of-archive)
  3. Managing the buffer and reading more data when needed

§Example

use tar_core::parse::{Parser, ParseEvent, Limits};

let mut parser = Parser::new(Limits::default());

// Simulated tar data (in practice, read from file/network)
let data = [0u8; 1024]; // Two zero blocks = end of archive

match parser.parse(&data) {
    Ok(ParseEvent::End { consumed }) => {
        println!("End of archive after {} bytes", consumed);
    }
    Ok(event) => {
        println!("Got event {:?}", event);
    }
    Err(e) => {
        eprintln!("Parse error: {}", e);
    }
}

Structs§

Limits
Configurable security limits for tar archive parsing.
ParsedEntry
A fully-resolved tar entry with all extensions applied.
Parser
Sans-IO tar archive parser.

Enums§

ParseError
Errors that can occur during tar archive parsing.
ParseEvent
Events emitted by the sans-IO parser.

Type Aliases§

Result
Result type for parsing operations.