Skip to content

Commit

Permalink
Add ability to parse section from in memory buffer
Browse files Browse the repository at this point in the history
Resolves: #12
  • Loading branch information
val-ms committed Oct 8, 2023
1 parent f940d8c commit c155f31
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/onenote/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::onestore::parse_store;
use crate::reader::Reader;
use std::ffi::OsStr;
use std::fs::File;
use std::io::{BufReader, Read};
use std::io::{BufReader, Read, Cursor};
use std::path::Path;

pub(crate) mod content;
Expand Down Expand Up @@ -76,6 +76,26 @@ impl Parser {
Ok(Notebook { entries: sections })
}

/// Parse a OneNote section buffer.
///
/// The `data` argument must contain a OneNote section.
pub fn parse_section_buffer(&mut self, data: &[u8], file_name: &str) -> Result<Section> {
let packaging = OneStorePackaging::parse(&mut Reader::new(data))?;
let store = parse_store(&packaging)?;

if store.schema_guid() != guid!({1F937CB4-B26F-445F-B9F8-17E20160E461}) {
return Err(ErrorKind::NotASectionFile {
file: file_name.to_string(),
}
.into());
}

section::parse_section(
store,
file_name.to_string(),
)
}

/// Parse a OneNote section file.
///
/// The `path` argument must point to a `.one` file that contains a
Expand Down

0 comments on commit c155f31

Please sign in to comment.