pub struct SolidArchive<T: Write> { /* private fields */ }Expand description
An object providing writing to a solid mode PNA file. An instance of an SolidArchive can be written.
§Examples
Creates a new solid mode PNA file and adds entry to it.
use libpna::{Archive, EntryBuilder, WriteOptions};
use std::fs::File;
let option = WriteOptions::builder().build();
let file = File::create("foo.pna")?;
let mut archive = Archive::write_solid_header(file, option)?;
let mut entry_builder = EntryBuilder::new_file("bar.txt".into(), WriteOptions::store())?;
entry_builder.write_all(b"content")?;
let entry = entry_builder.build()?;
archive.add_entry(entry)?;
archive.finalize()?;Implementations§
Source§impl<W: Write> SolidArchive<W>
impl<W: Write> SolidArchive<W>
Sourcepub fn add_entry<T>(&mut self, entry: NormalEntry<T>) -> Result<usize>where
NormalEntry<T>: Entry,
pub fn add_entry<T>(&mut self, entry: NormalEntry<T>) -> Result<usize>where
NormalEntry<T>: Entry,
Adds a new entry to the archive.
§Arguments
entry- The entry to add to the archive.
§Examples
use libpna::{Archive, EntryBuilder, WriteOptions};
use std::fs::File;
let option = WriteOptions::builder().build();
let file = File::create("example.pna")?;
let mut archive = Archive::write_solid_header(file, option)?;
archive
.add_entry(EntryBuilder::new_file("example.txt".into(), WriteOptions::store())?.build()?)?;
archive.finalize()?;Sourcepub fn write_file<F>(
&mut self,
name: EntryName,
metadata: Metadata,
f: F,
) -> Result<()>
pub fn write_file<F>( &mut self, name: EntryName, metadata: Metadata, f: F, ) -> Result<()>
Write a regular file as solid entry into archive.
§Example
use libpna::{Archive, Metadata, WriteOptions};
use std::fs;
use std::io::{self, prelude::*};
let file = fs::File::create("foo.pna")?;
let option = WriteOptions::builder().build();
let mut archive = Archive::write_solid_header(file, option)?;
archive.write_file("bar.txt".into(), Metadata::new(), |writer| {
writer.write_all(b"text")
})?;
archive.finalize()?;Sourcepub fn finalize(self) -> Result<W>
pub fn finalize(self) -> Result<W>
Write an end marker to finalize the archive.
Marks that the PNA archive contains no more entries. Normally, a PNA archive reader will continue reading entries in the hope that the entry exists until it encounters this end marker. This end marker should always be recorded at the end of the file unless there is a special reason to do so.
§Examples
Create an empty archive.
use libpna::{Archive, WriteOptions};
use std::fs::File;
let option = WriteOptions::builder().build();
let file = File::create("example.pna")?;
let mut archive = Archive::write_solid_header(file, option)?;
archive.finalize()?;Auto Trait Implementations§
impl<T> Freeze for SolidArchive<T>where
T: Freeze,
impl<T> RefUnwindSafe for SolidArchive<T>where
T: RefUnwindSafe,
impl<T> Send for SolidArchive<T>where
T: Send,
impl<T> Sync for SolidArchive<T>where
T: Sync,
impl<T> Unpin for SolidArchive<T>where
T: Unpin,
impl<T> !UnwindSafe for SolidArchive<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more