Skip to content

Commit 5a1c8ea

Browse files
authored
Add public constructor for PaxExtensions (#271)
1 parent 8333ef6 commit 5a1c8ea

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/entry.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use crate::archive::ArchiveInner;
1313
use crate::error::TarError;
1414
use crate::header::bytes2path;
1515
use crate::other;
16-
use crate::pax::pax_extensions;
1716
use crate::{Archive, Header, PaxExtensions};
1817

1918
/// A read-only view into an entry of an archive.
@@ -300,7 +299,7 @@ impl<'a> EntryFields<'a> {
300299
}
301300
None => {
302301
if let Some(ref pax) = self.pax_extensions {
303-
let pax = pax_extensions(pax)
302+
let pax = PaxExtensions::new(pax)
304303
.filter_map(|f| f.ok())
305304
.find(|f| f.key_bytes() == b"path")
306305
.map(|f| f.value_bytes());
@@ -336,7 +335,7 @@ impl<'a> EntryFields<'a> {
336335
}
337336
None => {
338337
if let Some(ref pax) = self.pax_extensions {
339-
let pax = pax_extensions(pax)
338+
let pax = PaxExtensions::new(pax)
340339
.filter_map(|f| f.ok())
341340
.find(|f| f.key_bytes() == b"linkpath")
342341
.map(|f| f.value_bytes());
@@ -358,7 +357,9 @@ impl<'a> EntryFields<'a> {
358357
}
359358
self.pax_extensions = Some(self.read_all()?);
360359
}
361-
Ok(Some(pax_extensions(self.pax_extensions.as_ref().unwrap())))
360+
Ok(Some(PaxExtensions::new(
361+
self.pax_extensions.as_ref().unwrap(),
362+
)))
362363
}
363364

364365
fn unpack_in(&mut self, dst: &Path) -> io::Result<bool> {

src/pax.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,26 @@ pub struct PaxExtensions<'entry> {
1212
data: slice::Split<'entry, u8, fn(&u8) -> bool>,
1313
}
1414

15+
impl<'entry> PaxExtensions<'entry> {
16+
/// Create new pax extensions iterator from the given entry data.
17+
pub fn new(a: &'entry [u8]) -> Self {
18+
fn is_newline(a: &u8) -> bool {
19+
*a == b'\n'
20+
}
21+
PaxExtensions {
22+
data: a.split(is_newline),
23+
}
24+
}
25+
}
26+
1527
/// A key/value pair corresponding to a pax extension.
1628
pub struct PaxExtension<'entry> {
1729
key: &'entry [u8],
1830
value: &'entry [u8],
1931
}
2032

21-
pub fn pax_extensions(a: &[u8]) -> PaxExtensions {
22-
fn is_newline(a: &u8) -> bool {
23-
*a == b'\n'
24-
}
25-
PaxExtensions {
26-
data: a.split(is_newline),
27-
}
28-
}
29-
3033
pub fn pax_extensions_size(a: &[u8]) -> Option<u64> {
31-
for extension in pax_extensions(a) {
34+
for extension in PaxExtensions::new(a) {
3235
let current_extension = match extension {
3336
Ok(ext) => ext,
3437
Err(_) => return None,

0 commit comments

Comments
 (0)