pub struct Builder { /* private fields */ }
Expand description
Builds metadata for one entry to be written into an archive.
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn new(name: &str) -> Self
pub fn new(name: &str) -> Self
Create the metadata for one CPIO entry
Examples found in repository?
More examples
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
fn main() {
// Set up our input files
let data1: &[u8] = b"Hello, World";
let length1 = data1.len() as u32;
let mut input1 = io::Cursor::new(data1);
let data2: &[u8] = b"Hello, World 2";
let length2 = data2.len() as u32;
let mut input2 = io::Cursor::new(data2);
// Set up our output file
let output = stdout();
// Set up the descriptor of our input file
let b = NewcBuilder::new("./hello_world")
.ino(1)
.uid(1000)
.gid(1000)
.mode(0o100644);
// and get a writer for that input file
let mut writer = b.write(output, length1);
// Copy the input file into our CPIO archive
io::copy(&mut input1, &mut writer).unwrap();
let output = writer.finish().unwrap();
// Set up the descriptor of an empty directory
let b = NewcBuilder::new("./empty_dir")
.ino(2)
.uid(1000)
.gid(1000)
.mode(0o000755)
.set_mode_file_type(cpio::newc::ModeFileType::Directory);
let writer = b.write(output, 0);
let output = writer.finish().unwrap();
// Set up the descriptor of our second input file
let b = NewcBuilder::new("./hello_world2")
.ino(3)
.uid(1000)
.gid(1000)
.mode(0o100644);
// and get a writer for that input file
let mut writer = b.write(output, length2);
// Copy the second input file into our CPIO archive
io::copy(&mut input2, &mut writer).unwrap();
let output = writer.finish().unwrap();
let data: &[u8] = b"./hello_world2";
let length = data.len() as u32;
let mut input = io::Cursor::new(data);
// Set up the descriptor for a symlink
let b = NewcBuilder::new("./hello-link")
.ino(4)
.uid(1000)
.gid(1000)
.mode(0o100644)
.set_mode_file_type(cpio::newc::ModeFileType::Symlink);
let mut writer = b.write(output, length);
io::copy(&mut input, &mut writer).unwrap();
let output = writer.finish().unwrap();
// Finish up by writing the trailer for the archive
let _ = trailer(output).unwrap();
}
Sourcepub fn ino(self, ino: u32) -> Self
pub fn ino(self, ino: u32) -> Self
Set the inode number for this file. In modern times however, typically this is just a a unique index ID for the file, rather than the actual inode number.
Examples found in repository?
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
fn main() {
// Set up our input files
let data1: &[u8] = b"Hello, World";
let length1 = data1.len() as u32;
let mut input1 = io::Cursor::new(data1);
let data2: &[u8] = b"Hello, World 2";
let length2 = data2.len() as u32;
let mut input2 = io::Cursor::new(data2);
// Set up our output file
let output = stdout();
// Set up the descriptor of our input file
let b = NewcBuilder::new("./hello_world")
.ino(1)
.uid(1000)
.gid(1000)
.mode(0o100644);
// and get a writer for that input file
let mut writer = b.write(output, length1);
// Copy the input file into our CPIO archive
io::copy(&mut input1, &mut writer).unwrap();
let output = writer.finish().unwrap();
// Set up the descriptor of an empty directory
let b = NewcBuilder::new("./empty_dir")
.ino(2)
.uid(1000)
.gid(1000)
.mode(0o000755)
.set_mode_file_type(cpio::newc::ModeFileType::Directory);
let writer = b.write(output, 0);
let output = writer.finish().unwrap();
// Set up the descriptor of our second input file
let b = NewcBuilder::new("./hello_world2")
.ino(3)
.uid(1000)
.gid(1000)
.mode(0o100644);
// and get a writer for that input file
let mut writer = b.write(output, length2);
// Copy the second input file into our CPIO archive
io::copy(&mut input2, &mut writer).unwrap();
let output = writer.finish().unwrap();
let data: &[u8] = b"./hello_world2";
let length = data.len() as u32;
let mut input = io::Cursor::new(data);
// Set up the descriptor for a symlink
let b = NewcBuilder::new("./hello-link")
.ino(4)
.uid(1000)
.gid(1000)
.mode(0o100644)
.set_mode_file_type(cpio::newc::ModeFileType::Symlink);
let mut writer = b.write(output, length);
io::copy(&mut input, &mut writer).unwrap();
let output = writer.finish().unwrap();
// Finish up by writing the trailer for the archive
let _ = trailer(output).unwrap();
}
Sourcepub fn mode(self, mode: u32) -> Self
pub fn mode(self, mode: u32) -> Self
Set the file’s “mode” - the same as an inode “mode” field - containing permission bits and a bit of metadata about the type of file represented.
Examples found in repository?
More examples
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
fn main() {
// Set up our input files
let data1: &[u8] = b"Hello, World";
let length1 = data1.len() as u32;
let mut input1 = io::Cursor::new(data1);
let data2: &[u8] = b"Hello, World 2";
let length2 = data2.len() as u32;
let mut input2 = io::Cursor::new(data2);
// Set up our output file
let output = stdout();
// Set up the descriptor of our input file
let b = NewcBuilder::new("./hello_world")
.ino(1)
.uid(1000)
.gid(1000)
.mode(0o100644);
// and get a writer for that input file
let mut writer = b.write(output, length1);
// Copy the input file into our CPIO archive
io::copy(&mut input1, &mut writer).unwrap();
let output = writer.finish().unwrap();
// Set up the descriptor of an empty directory
let b = NewcBuilder::new("./empty_dir")
.ino(2)
.uid(1000)
.gid(1000)
.mode(0o000755)
.set_mode_file_type(cpio::newc::ModeFileType::Directory);
let writer = b.write(output, 0);
let output = writer.finish().unwrap();
// Set up the descriptor of our second input file
let b = NewcBuilder::new("./hello_world2")
.ino(3)
.uid(1000)
.gid(1000)
.mode(0o100644);
// and get a writer for that input file
let mut writer = b.write(output, length2);
// Copy the second input file into our CPIO archive
io::copy(&mut input2, &mut writer).unwrap();
let output = writer.finish().unwrap();
let data: &[u8] = b"./hello_world2";
let length = data.len() as u32;
let mut input = io::Cursor::new(data);
// Set up the descriptor for a symlink
let b = NewcBuilder::new("./hello-link")
.ino(4)
.uid(1000)
.gid(1000)
.mode(0o100644)
.set_mode_file_type(cpio::newc::ModeFileType::Symlink);
let mut writer = b.write(output, length);
io::copy(&mut input, &mut writer).unwrap();
let output = writer.finish().unwrap();
// Finish up by writing the trailer for the archive
let _ = trailer(output).unwrap();
}
Sourcepub fn uid(self, uid: u32) -> Self
pub fn uid(self, uid: u32) -> Self
Set this file’s UID.
Examples found in repository?
More examples
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
fn main() {
// Set up our input files
let data1: &[u8] = b"Hello, World";
let length1 = data1.len() as u32;
let mut input1 = io::Cursor::new(data1);
let data2: &[u8] = b"Hello, World 2";
let length2 = data2.len() as u32;
let mut input2 = io::Cursor::new(data2);
// Set up our output file
let output = stdout();
// Set up the descriptor of our input file
let b = NewcBuilder::new("./hello_world")
.ino(1)
.uid(1000)
.gid(1000)
.mode(0o100644);
// and get a writer for that input file
let mut writer = b.write(output, length1);
// Copy the input file into our CPIO archive
io::copy(&mut input1, &mut writer).unwrap();
let output = writer.finish().unwrap();
// Set up the descriptor of an empty directory
let b = NewcBuilder::new("./empty_dir")
.ino(2)
.uid(1000)
.gid(1000)
.mode(0o000755)
.set_mode_file_type(cpio::newc::ModeFileType::Directory);
let writer = b.write(output, 0);
let output = writer.finish().unwrap();
// Set up the descriptor of our second input file
let b = NewcBuilder::new("./hello_world2")
.ino(3)
.uid(1000)
.gid(1000)
.mode(0o100644);
// and get a writer for that input file
let mut writer = b.write(output, length2);
// Copy the second input file into our CPIO archive
io::copy(&mut input2, &mut writer).unwrap();
let output = writer.finish().unwrap();
let data: &[u8] = b"./hello_world2";
let length = data.len() as u32;
let mut input = io::Cursor::new(data);
// Set up the descriptor for a symlink
let b = NewcBuilder::new("./hello-link")
.ino(4)
.uid(1000)
.gid(1000)
.mode(0o100644)
.set_mode_file_type(cpio::newc::ModeFileType::Symlink);
let mut writer = b.write(output, length);
io::copy(&mut input, &mut writer).unwrap();
let output = writer.finish().unwrap();
// Finish up by writing the trailer for the archive
let _ = trailer(output).unwrap();
}
Sourcepub fn gid(self, gid: u32) -> Self
pub fn gid(self, gid: u32) -> Self
Set this file’s GID.
Examples found in repository?
More examples
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
fn main() {
// Set up our input files
let data1: &[u8] = b"Hello, World";
let length1 = data1.len() as u32;
let mut input1 = io::Cursor::new(data1);
let data2: &[u8] = b"Hello, World 2";
let length2 = data2.len() as u32;
let mut input2 = io::Cursor::new(data2);
// Set up our output file
let output = stdout();
// Set up the descriptor of our input file
let b = NewcBuilder::new("./hello_world")
.ino(1)
.uid(1000)
.gid(1000)
.mode(0o100644);
// and get a writer for that input file
let mut writer = b.write(output, length1);
// Copy the input file into our CPIO archive
io::copy(&mut input1, &mut writer).unwrap();
let output = writer.finish().unwrap();
// Set up the descriptor of an empty directory
let b = NewcBuilder::new("./empty_dir")
.ino(2)
.uid(1000)
.gid(1000)
.mode(0o000755)
.set_mode_file_type(cpio::newc::ModeFileType::Directory);
let writer = b.write(output, 0);
let output = writer.finish().unwrap();
// Set up the descriptor of our second input file
let b = NewcBuilder::new("./hello_world2")
.ino(3)
.uid(1000)
.gid(1000)
.mode(0o100644);
// and get a writer for that input file
let mut writer = b.write(output, length2);
// Copy the second input file into our CPIO archive
io::copy(&mut input2, &mut writer).unwrap();
let output = writer.finish().unwrap();
let data: &[u8] = b"./hello_world2";
let length = data.len() as u32;
let mut input = io::Cursor::new(data);
// Set up the descriptor for a symlink
let b = NewcBuilder::new("./hello-link")
.ino(4)
.uid(1000)
.gid(1000)
.mode(0o100644)
.set_mode_file_type(cpio::newc::ModeFileType::Symlink);
let mut writer = b.write(output, length);
io::copy(&mut input, &mut writer).unwrap();
let output = writer.finish().unwrap();
// Finish up by writing the trailer for the archive
let _ = trailer(output).unwrap();
}
Sourcepub fn dev_major(self, dev_major: u32) -> Self
pub fn dev_major(self, dev_major: u32) -> Self
Set the major component of the device ID, describing the device on which this file resides.
Device IDs are comprised of a major and minor component. The major component identifies the class of device, while the minor component identifies a specific device of that class.
Sourcepub fn dev_minor(self, dev_minor: u32) -> Self
pub fn dev_minor(self, dev_minor: u32) -> Self
Set the minor component of the device ID, describing the device on which this file resides.
Device IDs are comprised of a major and minor component. The major component identifies the class of device, while the minor component identifies a specific device of that class.
Sourcepub fn rdev_major(self, rdev_major: u32) -> Self
pub fn rdev_major(self, rdev_major: u32) -> Self
Set the major component of the rdev ID, describes the device that this file (inode) represents.
Device IDs are comprised of a major and minor component. The major component identifies the class of device, while the minor component identifies a specific device of that class.
Sourcepub fn rdev_minor(self, rdev_minor: u32) -> Self
pub fn rdev_minor(self, rdev_minor: u32) -> Self
Set the minor component of the rdev ID, field describes the device that this file (inode) represents.
Device IDs are comprised of a major and minor component. The major component identifies the class of device, while the minor component identifies a specific device of that class.
Sourcepub fn set_mode_file_type(self, file_type: ModeFileType) -> Self
pub fn set_mode_file_type(self, file_type: ModeFileType) -> Self
Set the mode file type of the entry
Examples found in repository?
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
fn main() {
// Set up our input files
let data1: &[u8] = b"Hello, World";
let length1 = data1.len() as u32;
let mut input1 = io::Cursor::new(data1);
let data2: &[u8] = b"Hello, World 2";
let length2 = data2.len() as u32;
let mut input2 = io::Cursor::new(data2);
// Set up our output file
let output = stdout();
// Set up the descriptor of our input file
let b = NewcBuilder::new("./hello_world")
.ino(1)
.uid(1000)
.gid(1000)
.mode(0o100644);
// and get a writer for that input file
let mut writer = b.write(output, length1);
// Copy the input file into our CPIO archive
io::copy(&mut input1, &mut writer).unwrap();
let output = writer.finish().unwrap();
// Set up the descriptor of an empty directory
let b = NewcBuilder::new("./empty_dir")
.ino(2)
.uid(1000)
.gid(1000)
.mode(0o000755)
.set_mode_file_type(cpio::newc::ModeFileType::Directory);
let writer = b.write(output, 0);
let output = writer.finish().unwrap();
// Set up the descriptor of our second input file
let b = NewcBuilder::new("./hello_world2")
.ino(3)
.uid(1000)
.gid(1000)
.mode(0o100644);
// and get a writer for that input file
let mut writer = b.write(output, length2);
// Copy the second input file into our CPIO archive
io::copy(&mut input2, &mut writer).unwrap();
let output = writer.finish().unwrap();
let data: &[u8] = b"./hello_world2";
let length = data.len() as u32;
let mut input = io::Cursor::new(data);
// Set up the descriptor for a symlink
let b = NewcBuilder::new("./hello-link")
.ino(4)
.uid(1000)
.gid(1000)
.mode(0o100644)
.set_mode_file_type(cpio::newc::ModeFileType::Symlink);
let mut writer = b.write(output, length);
io::copy(&mut input, &mut writer).unwrap();
let output = writer.finish().unwrap();
// Finish up by writing the trailer for the archive
let _ = trailer(output).unwrap();
}
Sourcepub fn write<W: Write>(self, w: W, file_size: u32) -> Writer<W> ⓘ
pub fn write<W: Write>(self, w: W, file_size: u32) -> Writer<W> ⓘ
Write out an entry to the provided writer in SVR4 “new ascii” CPIO format.
Examples found in repository?
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
fn main() {
// Set up our input files
let data1: &[u8] = b"Hello, World";
let length1 = data1.len() as u32;
let mut input1 = io::Cursor::new(data1);
let data2: &[u8] = b"Hello, World 2";
let length2 = data2.len() as u32;
let mut input2 = io::Cursor::new(data2);
// Set up our output file
let output = stdout();
// Set up the descriptor of our input file
let b = NewcBuilder::new("./hello_world")
.ino(1)
.uid(1000)
.gid(1000)
.mode(0o100644);
// and get a writer for that input file
let mut writer = b.write(output, length1);
// Copy the input file into our CPIO archive
io::copy(&mut input1, &mut writer).unwrap();
let output = writer.finish().unwrap();
// Set up the descriptor of an empty directory
let b = NewcBuilder::new("./empty_dir")
.ino(2)
.uid(1000)
.gid(1000)
.mode(0o000755)
.set_mode_file_type(cpio::newc::ModeFileType::Directory);
let writer = b.write(output, 0);
let output = writer.finish().unwrap();
// Set up the descriptor of our second input file
let b = NewcBuilder::new("./hello_world2")
.ino(3)
.uid(1000)
.gid(1000)
.mode(0o100644);
// and get a writer for that input file
let mut writer = b.write(output, length2);
// Copy the second input file into our CPIO archive
io::copy(&mut input2, &mut writer).unwrap();
let output = writer.finish().unwrap();
let data: &[u8] = b"./hello_world2";
let length = data.len() as u32;
let mut input = io::Cursor::new(data);
// Set up the descriptor for a symlink
let b = NewcBuilder::new("./hello-link")
.ino(4)
.uid(1000)
.gid(1000)
.mode(0o100644)
.set_mode_file_type(cpio::newc::ModeFileType::Symlink);
let mut writer = b.write(output, length);
io::copy(&mut input, &mut writer).unwrap();
let output = writer.finish().unwrap();
// Finish up by writing the trailer for the archive
let _ = trailer(output).unwrap();
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Builder
impl RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnwindSafe for Builder
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)