Skip to content

Commit

Permalink
🚚 ReadEntry to RegularEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanTsune committed Nov 17, 2023
1 parent 6f0a59d commit 3f094da
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
4 changes: 2 additions & 2 deletions cli/src/command/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
};
use glob::Pattern;
use indicatif::{HumanDuration, ProgressBar, ProgressStyle};
use libpna::{Archive, DataKind, Permission, ReadEntry, ReadOption};
use libpna::{Archive, DataKind, Permission, ReadOption, RegularEntry};
#[cfg(unix)]
use nix::unistd::{chown, Group, User};
use rayon::{prelude::*, ThreadPoolBuilder};
Expand Down Expand Up @@ -130,7 +130,7 @@ fn extract_archive(args: ExtractArgs, verbosity: Verbosity) -> io::Result<()> {

fn extract_entry(
item_path: PathBuf,
item: ReadEntry,
item: RegularEntry,
password: Option<String>,
overwrite: bool,
out_dir: Option<PathBuf>,
Expand Down
6 changes: 3 additions & 3 deletions cli/src/command/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
use ansi_term::{ANSIString, Colour, Style};
use chrono::{DateTime, Local};
use glob::Pattern;
use libpna::{Archive, Compression, DataKind, Encryption, ReadEntry, ReadOption};
use libpna::{Archive, Compression, DataKind, Encryption, ReadOption, RegularEntry};
use rayon::prelude::*;
use std::{
fs::File,
Expand Down Expand Up @@ -86,13 +86,13 @@ fn list_archive(args: ListArgs, _: Verbosity) -> io::Result<()> {
Ok(())
}

fn simple_list_entries(entries: &[ReadEntry]) {
fn simple_list_entries(entries: &[RegularEntry]) {
for entry in entries {
println!("{}", entry.header().path())
}
}

fn detail_list_entries(entries: Vec<ReadEntry>, password: Option<&str>, print_header: bool) {
fn detail_list_entries(entries: Vec<RegularEntry>, password: Option<&str>, print_header: bool) {
let now = SystemTime::now();
let style_encryption_column = Style::new().fg(Colour::Purple);
let style_compression_column = Style::new().fg(Colour::Blue);
Expand Down
19 changes: 11 additions & 8 deletions lib/src/archive/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl<R: Read> Read for EntryReader<R> {
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub(crate) enum EntryContainer {
Solid(SolidReadEntry),
Regular(ReadEntry),
Regular(RegularEntry),
}

impl TryFrom<ChunkEntry> for EntryContainer {
Expand All @@ -119,7 +119,7 @@ impl TryFrom<ChunkEntry> for EntryContainer {
if let Some(first_chunk) = entry.0.first() {
match first_chunk.ty {
ChunkType::SHED => Ok(Self::Solid(SolidReadEntry::try_from(entry)?)),
ChunkType::FHED => Ok(Self::Regular(ReadEntry::try_from(entry)?)),
ChunkType::FHED => Ok(Self::Regular(RegularEntry::try_from(entry)?)),
_ => Err(io::Error::new(io::ErrorKind::InvalidData, "Invalid entry")),
}
} else {
Expand All @@ -131,7 +131,7 @@ impl TryFrom<ChunkEntry> for EntryContainer {
pub(crate) struct EntryIterator<'s>(EntryReader<&'s [u8]>);

impl Iterator for EntryIterator<'_> {
type Item = io::Result<ReadEntry>;
type Item = io::Result<RegularEntry>;

fn next(&mut self) -> Option<Self::Item> {
let mut chunk_reader = ChunkReader::from(&mut self.0);
Expand Down Expand Up @@ -266,17 +266,20 @@ impl TryFrom<ChunkEntry> for SolidReadEntry {
}
}

#[deprecated(since = "0.4.0", note = "`ReadEntry` is renamed to `RegularEntry`")]
pub type ReadEntry = RegularEntry;

/// [Entry] that read from PNA archive.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct ReadEntry {
pub struct RegularEntry {
pub(crate) header: EntryHeader,
pub(crate) phsf: Option<String>,
pub(crate) extra: Vec<RawChunk>,
pub(crate) data: Vec<Vec<u8>>,
pub(crate) metadata: Metadata,
}

impl TryFrom<ChunkEntry> for ReadEntry {
impl TryFrom<ChunkEntry> for RegularEntry {
type Error = io::Error;
fn try_from(entry: ChunkEntry) -> Result<Self, Self::Error> {
if let Some(first_chunk) = entry.0.first() {
Expand Down Expand Up @@ -347,7 +350,7 @@ impl TryFrom<ChunkEntry> for ReadEntry {
}
}

impl SealedIntoChunks for ReadEntry {
impl SealedIntoChunks for RegularEntry {
fn into_chunks(self) -> Vec<RawChunk> {
let mut vec = Vec::new();
vec.push(RawChunk::from_data(ChunkType::FHED, self.header.to_bytes()));
Expand Down Expand Up @@ -388,7 +391,7 @@ impl SealedIntoChunks for ReadEntry {
}
}

impl Entry for ReadEntry {
impl Entry for RegularEntry {
#[inline]
fn bytes_len(&self) -> usize {
self.clone().into_bytes().len()
Expand All @@ -403,7 +406,7 @@ impl Entry for ReadEntry {
}
}

impl ReadEntry {
impl RegularEntry {
#[inline]
pub fn header(&self) -> &EntryHeader {
&self.header
Expand Down
6 changes: 3 additions & 3 deletions lib/src/archive/entry/builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
archive::entry::{
writer_and_hash, Entry, EntryContainer, EntryHeader, EntryName, EntryReference, Metadata,
Permission, ReadEntry, SolidEntries, SolidHeader, SolidReadEntry, WriteOption,
Permission, RegularEntry, SolidEntries, SolidHeader, SolidReadEntry, WriteOption,
},
cipher::CipherWriter,
compress::CompressionWriter,
Expand Down Expand Up @@ -202,7 +202,7 @@ impl EntryBuilder {
Ok(EntryContainer::Regular(self.build_as_entry()?))
}

fn build_as_entry(self) -> io::Result<ReadEntry> {
fn build_as_entry(self) -> io::Result<RegularEntry> {
let data = if let Some(data) = self.data {
data.try_into_inner()?.try_into_inner()?.inner
} else {
Expand All @@ -214,7 +214,7 @@ impl EntryBuilder {
modified: self.last_modified,
permission: self.permission,
};
Ok(ReadEntry {
Ok(RegularEntry {
header: self.header,
phsf: self.phsf,
extra: Vec::new(),
Expand Down
12 changes: 6 additions & 6 deletions lib/src/archive/read.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
archive::{Archive, ArchiveHeader, ChunkEntry, EntryContainer, ReadEntry, PNA_HEADER},
archive::{Archive, ArchiveHeader, ChunkEntry, EntryContainer, RegularEntry, PNA_HEADER},
chunk::{Chunk, ChunkReader, ChunkType, RawChunk},
};
use std::{
Expand Down Expand Up @@ -99,7 +99,7 @@ impl<R: Read> Archive<R> {
/// Returns an error if an I/O error occurs while reading from the archive.
#[deprecated(since = "0.2.0")]
#[inline]
pub fn read(&mut self) -> io::Result<Option<ReadEntry>> {
pub fn read(&mut self) -> io::Result<Option<RegularEntry>> {
loop {
let entry = self.read_entry()?;
return match entry {
Expand Down Expand Up @@ -133,7 +133,7 @@ impl<R: Read> Archive<R> {
///
/// An iterator over the entries in the archive.
#[inline]
pub fn entries(&mut self) -> impl Iterator<Item = io::Result<ReadEntry>> + '_ {
pub fn entries(&mut self) -> impl Iterator<Item = io::Result<RegularEntry>> + '_ {
Entries::new(self)
}

Expand All @@ -145,7 +145,7 @@ impl<R: Read> Archive<R> {
pub fn entries_with_password(
&mut self,
password: Option<String>,
) -> impl Iterator<Item = io::Result<ReadEntry>> + '_ {
) -> impl Iterator<Item = io::Result<RegularEntry>> + '_ {
Entries::new_with_password(self, password)
}

Expand Down Expand Up @@ -193,7 +193,7 @@ impl<R: Read> Archive<R> {
pub(crate) struct Entries<'r, R: Read> {
reader: &'r mut Archive<R>,
password: Option<Option<String>>,
buf: VecDeque<io::Result<ReadEntry>>,
buf: VecDeque<io::Result<RegularEntry>>,
}

impl<'r, R: Read> Entries<'r, R> {
Expand All @@ -215,7 +215,7 @@ impl<'r, R: Read> Entries<'r, R> {
}

impl<'r, R: Read> Iterator for Entries<'r, R> {
type Item = io::Result<ReadEntry>;
type Item = io::Result<RegularEntry>;

fn next(&mut self) -> Option<Self::Item> {
if let Some(entry) = self.buf.pop_front() {
Expand Down

0 comments on commit 3f094da

Please sign in to comment.