2 unstable releases

0.1.0 Dec 12, 2022
0.0.1 Sep 29, 2022

#542 in Compression

49 downloads per month

MIT/Apache

57KB
1K SLoC

This crate provides a library to store and load documentation content in a single file.

Content is organized into pages. The collection of pages is a book. Both pages and books can contain metadata entries.

Books

The main type in the crate is Book. A Book may contains multiple pages and metadata entries.

Creating a New Book

New books are created with BookBuilder.

Content is added with add_metadata and new_page.

When the book is completed, it can be persisted with dump.

Optionally, data can be compressed with set_compression.

Example

use theory::{MetadataEntry, Book, Page};
use std::io::{Cursor, Read, Write};

let mut buffer: Vec<u8> = Vec::new();

let mut builder = Book::builder();
builder.new_page("First").set_content("1");
builder.new_page("Second").set_content("2");

builder
    .add_metadata(MetadataEntry::Title("Theory Example".into()))
    .dump(Cursor::new(&mut buffer));

let book = Book::load(Cursor::new(buffer)).unwrap();

assert_eq!(book.num_pages(), 2);

Loading a Book

A book written by BookBuilder::dump can be loaded with Book::load.

Crate Features

Features can be used for controlling some functionalities in the library:

  • deflate

    Add supports for compressing books with DEFLATE.

  • lz4

    Add supports for compressing books with LZ4.

All features are enabled by default.

Dependencies

~0.7–1.3MB
~33K SLoC