diff --git a/src/pax.rs b/src/pax.rs index d1494282..6c60f634 100644 --- a/src/pax.rs +++ b/src/pax.rs @@ -147,7 +147,7 @@ impl<'entry> PaxExtension<'entry> { } } -/// Extension trait for `Builder` to append PAX extended headers. +/// Implement `Builder` to append PAX extended headers. impl crate::Builder { /// Append PAX extended headers to the archive. /// @@ -156,7 +156,7 @@ impl crate::Builder { /// Returns io::Error if an error occurs, else it returns () pub fn append_pax_extensions<'key, 'value>( &mut self, - headers: impl IntoIterator, + headers: impl IntoIterator, ) -> Result<(), io::Error> { // Store the headers formatted before write let mut data: Vec = Vec::new(); @@ -172,7 +172,9 @@ impl crate::Builder { max_len *= 10; } let len = rest_len + len_len; - write!(&mut data, "{} {}=", len, key)?; + write!(&mut data, "{} ", len)?; + data.extend_from_slice(key); + data.push(b'='); data.extend_from_slice(value); data.push(b'\n'); } diff --git a/tests/all.rs b/tests/all.rs index 0e1c2613..42a2597c 100644 --- a/tests/all.rs +++ b/tests/all.rs @@ -933,8 +933,11 @@ fn pax_simple_write() { let mut ar: Builder> = Builder::new(BufWriter::new(file)); let pax_extensions = [ - ("arbitrary_pax_key", b"arbitrary_pax_value".as_slice()), - ("SCHILY.xattr.security.selinux", b"foo_t"), + ( + b"arbitrary_pax_key".as_slice(), + b"arbitrary_pax_value".as_slice(), + ), + (b"SCHILY.xattr.security.selinux".as_slice(), b"foo_t"), ]; t!(ar.append_pax_extensions(pax_extensions)); @@ -953,7 +956,10 @@ fn pax_simple_write() { assert_eq!(pax_arbitrary.key(), Ok("arbitrary_pax_key")); assert_eq!(pax_arbitrary.value(), Ok("arbitrary_pax_value")); let xattr = t!(pax_headers.next().unwrap()); - assert_eq!(xattr.key().unwrap(), pax_extensions[1].0); + assert_eq!( + xattr.key().unwrap(), + std::str::from_utf8(pax_extensions[1].0).unwrap() + ); assert_eq!(xattr.value_bytes(), pax_extensions[1].1); assert!(entries.next().is_none());