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
6fn main() {
7 // Set up our input files
8 let data1: &[u8] = b"Hello, World";
9 let length1 = data1.len() as u32;
10 let mut input1 = io::Cursor::new(data1);
11
12 let data2: &[u8] = b"Hello, World 2";
13 let length2 = data2.len() as u32;
14 let mut input2 = io::Cursor::new(data2);
15
16 // Set up our output file
17 let output = stdout();
18
19 // Set up the descriptor of our input file
20 let b = NewcBuilder::new("./hello_world")
21 .ino(1)
22 .uid(1000)
23 .gid(1000)
24 .mode(0o100644);
25 // and get a writer for that input file
26 let mut writer = b.write(output, length1);
27
28 // Copy the input file into our CPIO archive
29 io::copy(&mut input1, &mut writer).unwrap();
30 let output = writer.finish().unwrap();
31
32 // Set up the descriptor of an empty directory
33 let b = NewcBuilder::new("./empty_dir")
34 .ino(2)
35 .uid(1000)
36 .gid(1000)
37 .mode(0o000755)
38 .set_mode_file_type(cpio::newc::ModeFileType::Directory);
39 let writer = b.write(output, 0);
40 let output = writer.finish().unwrap();
41
42 // Set up the descriptor of our second input file
43 let b = NewcBuilder::new("./hello_world2")
44 .ino(3)
45 .uid(1000)
46 .gid(1000)
47 .mode(0o100644);
48 // and get a writer for that input file
49 let mut writer = b.write(output, length2);
50
51 // Copy the second input file into our CPIO archive
52 io::copy(&mut input2, &mut writer).unwrap();
53 let output = writer.finish().unwrap();
54
55 let data: &[u8] = b"./hello_world2";
56 let length = data.len() as u32;
57 let mut input = io::Cursor::new(data);
58
59 // Set up the descriptor for a symlink
60 let b = NewcBuilder::new("./hello-link")
61 .ino(4)
62 .uid(1000)
63 .gid(1000)
64 .mode(0o100644)
65 .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
66 let mut writer = b.write(output, length);
67 io::copy(&mut input, &mut writer).unwrap();
68 let output = writer.finish().unwrap();
69
70 // Finish up by writing the trailer for the archive
71 let _ = trailer(output).unwrap();
72}
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?
6fn main() {
7 // Set up our input files
8 let data1: &[u8] = b"Hello, World";
9 let length1 = data1.len() as u32;
10 let mut input1 = io::Cursor::new(data1);
11
12 let data2: &[u8] = b"Hello, World 2";
13 let length2 = data2.len() as u32;
14 let mut input2 = io::Cursor::new(data2);
15
16 // Set up our output file
17 let output = stdout();
18
19 // Set up the descriptor of our input file
20 let b = NewcBuilder::new("./hello_world")
21 .ino(1)
22 .uid(1000)
23 .gid(1000)
24 .mode(0o100644);
25 // and get a writer for that input file
26 let mut writer = b.write(output, length1);
27
28 // Copy the input file into our CPIO archive
29 io::copy(&mut input1, &mut writer).unwrap();
30 let output = writer.finish().unwrap();
31
32 // Set up the descriptor of an empty directory
33 let b = NewcBuilder::new("./empty_dir")
34 .ino(2)
35 .uid(1000)
36 .gid(1000)
37 .mode(0o000755)
38 .set_mode_file_type(cpio::newc::ModeFileType::Directory);
39 let writer = b.write(output, 0);
40 let output = writer.finish().unwrap();
41
42 // Set up the descriptor of our second input file
43 let b = NewcBuilder::new("./hello_world2")
44 .ino(3)
45 .uid(1000)
46 .gid(1000)
47 .mode(0o100644);
48 // and get a writer for that input file
49 let mut writer = b.write(output, length2);
50
51 // Copy the second input file into our CPIO archive
52 io::copy(&mut input2, &mut writer).unwrap();
53 let output = writer.finish().unwrap();
54
55 let data: &[u8] = b"./hello_world2";
56 let length = data.len() as u32;
57 let mut input = io::Cursor::new(data);
58
59 // Set up the descriptor for a symlink
60 let b = NewcBuilder::new("./hello-link")
61 .ino(4)
62 .uid(1000)
63 .gid(1000)
64 .mode(0o100644)
65 .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
66 let mut writer = b.write(output, length);
67 io::copy(&mut input, &mut writer).unwrap();
68 let output = writer.finish().unwrap();
69
70 // Finish up by writing the trailer for the archive
71 let _ = trailer(output).unwrap();
72}
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
6fn main() {
7 // Set up our input files
8 let data1: &[u8] = b"Hello, World";
9 let length1 = data1.len() as u32;
10 let mut input1 = io::Cursor::new(data1);
11
12 let data2: &[u8] = b"Hello, World 2";
13 let length2 = data2.len() as u32;
14 let mut input2 = io::Cursor::new(data2);
15
16 // Set up our output file
17 let output = stdout();
18
19 // Set up the descriptor of our input file
20 let b = NewcBuilder::new("./hello_world")
21 .ino(1)
22 .uid(1000)
23 .gid(1000)
24 .mode(0o100644);
25 // and get a writer for that input file
26 let mut writer = b.write(output, length1);
27
28 // Copy the input file into our CPIO archive
29 io::copy(&mut input1, &mut writer).unwrap();
30 let output = writer.finish().unwrap();
31
32 // Set up the descriptor of an empty directory
33 let b = NewcBuilder::new("./empty_dir")
34 .ino(2)
35 .uid(1000)
36 .gid(1000)
37 .mode(0o000755)
38 .set_mode_file_type(cpio::newc::ModeFileType::Directory);
39 let writer = b.write(output, 0);
40 let output = writer.finish().unwrap();
41
42 // Set up the descriptor of our second input file
43 let b = NewcBuilder::new("./hello_world2")
44 .ino(3)
45 .uid(1000)
46 .gid(1000)
47 .mode(0o100644);
48 // and get a writer for that input file
49 let mut writer = b.write(output, length2);
50
51 // Copy the second input file into our CPIO archive
52 io::copy(&mut input2, &mut writer).unwrap();
53 let output = writer.finish().unwrap();
54
55 let data: &[u8] = b"./hello_world2";
56 let length = data.len() as u32;
57 let mut input = io::Cursor::new(data);
58
59 // Set up the descriptor for a symlink
60 let b = NewcBuilder::new("./hello-link")
61 .ino(4)
62 .uid(1000)
63 .gid(1000)
64 .mode(0o100644)
65 .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
66 let mut writer = b.write(output, length);
67 io::copy(&mut input, &mut writer).unwrap();
68 let output = writer.finish().unwrap();
69
70 // Finish up by writing the trailer for the archive
71 let _ = trailer(output).unwrap();
72}
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
6fn main() {
7 // Set up our input files
8 let data1: &[u8] = b"Hello, World";
9 let length1 = data1.len() as u32;
10 let mut input1 = io::Cursor::new(data1);
11
12 let data2: &[u8] = b"Hello, World 2";
13 let length2 = data2.len() as u32;
14 let mut input2 = io::Cursor::new(data2);
15
16 // Set up our output file
17 let output = stdout();
18
19 // Set up the descriptor of our input file
20 let b = NewcBuilder::new("./hello_world")
21 .ino(1)
22 .uid(1000)
23 .gid(1000)
24 .mode(0o100644);
25 // and get a writer for that input file
26 let mut writer = b.write(output, length1);
27
28 // Copy the input file into our CPIO archive
29 io::copy(&mut input1, &mut writer).unwrap();
30 let output = writer.finish().unwrap();
31
32 // Set up the descriptor of an empty directory
33 let b = NewcBuilder::new("./empty_dir")
34 .ino(2)
35 .uid(1000)
36 .gid(1000)
37 .mode(0o000755)
38 .set_mode_file_type(cpio::newc::ModeFileType::Directory);
39 let writer = b.write(output, 0);
40 let output = writer.finish().unwrap();
41
42 // Set up the descriptor of our second input file
43 let b = NewcBuilder::new("./hello_world2")
44 .ino(3)
45 .uid(1000)
46 .gid(1000)
47 .mode(0o100644);
48 // and get a writer for that input file
49 let mut writer = b.write(output, length2);
50
51 // Copy the second input file into our CPIO archive
52 io::copy(&mut input2, &mut writer).unwrap();
53 let output = writer.finish().unwrap();
54
55 let data: &[u8] = b"./hello_world2";
56 let length = data.len() as u32;
57 let mut input = io::Cursor::new(data);
58
59 // Set up the descriptor for a symlink
60 let b = NewcBuilder::new("./hello-link")
61 .ino(4)
62 .uid(1000)
63 .gid(1000)
64 .mode(0o100644)
65 .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
66 let mut writer = b.write(output, length);
67 io::copy(&mut input, &mut writer).unwrap();
68 let output = writer.finish().unwrap();
69
70 // Finish up by writing the trailer for the archive
71 let _ = trailer(output).unwrap();
72}
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
6fn main() {
7 // Set up our input files
8 let data1: &[u8] = b"Hello, World";
9 let length1 = data1.len() as u32;
10 let mut input1 = io::Cursor::new(data1);
11
12 let data2: &[u8] = b"Hello, World 2";
13 let length2 = data2.len() as u32;
14 let mut input2 = io::Cursor::new(data2);
15
16 // Set up our output file
17 let output = stdout();
18
19 // Set up the descriptor of our input file
20 let b = NewcBuilder::new("./hello_world")
21 .ino(1)
22 .uid(1000)
23 .gid(1000)
24 .mode(0o100644);
25 // and get a writer for that input file
26 let mut writer = b.write(output, length1);
27
28 // Copy the input file into our CPIO archive
29 io::copy(&mut input1, &mut writer).unwrap();
30 let output = writer.finish().unwrap();
31
32 // Set up the descriptor of an empty directory
33 let b = NewcBuilder::new("./empty_dir")
34 .ino(2)
35 .uid(1000)
36 .gid(1000)
37 .mode(0o000755)
38 .set_mode_file_type(cpio::newc::ModeFileType::Directory);
39 let writer = b.write(output, 0);
40 let output = writer.finish().unwrap();
41
42 // Set up the descriptor of our second input file
43 let b = NewcBuilder::new("./hello_world2")
44 .ino(3)
45 .uid(1000)
46 .gid(1000)
47 .mode(0o100644);
48 // and get a writer for that input file
49 let mut writer = b.write(output, length2);
50
51 // Copy the second input file into our CPIO archive
52 io::copy(&mut input2, &mut writer).unwrap();
53 let output = writer.finish().unwrap();
54
55 let data: &[u8] = b"./hello_world2";
56 let length = data.len() as u32;
57 let mut input = io::Cursor::new(data);
58
59 // Set up the descriptor for a symlink
60 let b = NewcBuilder::new("./hello-link")
61 .ino(4)
62 .uid(1000)
63 .gid(1000)
64 .mode(0o100644)
65 .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
66 let mut writer = b.write(output, length);
67 io::copy(&mut input, &mut writer).unwrap();
68 let output = writer.finish().unwrap();
69
70 // Finish up by writing the trailer for the archive
71 let _ = trailer(output).unwrap();
72}
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?
6fn main() {
7 // Set up our input files
8 let data1: &[u8] = b"Hello, World";
9 let length1 = data1.len() as u32;
10 let mut input1 = io::Cursor::new(data1);
11
12 let data2: &[u8] = b"Hello, World 2";
13 let length2 = data2.len() as u32;
14 let mut input2 = io::Cursor::new(data2);
15
16 // Set up our output file
17 let output = stdout();
18
19 // Set up the descriptor of our input file
20 let b = NewcBuilder::new("./hello_world")
21 .ino(1)
22 .uid(1000)
23 .gid(1000)
24 .mode(0o100644);
25 // and get a writer for that input file
26 let mut writer = b.write(output, length1);
27
28 // Copy the input file into our CPIO archive
29 io::copy(&mut input1, &mut writer).unwrap();
30 let output = writer.finish().unwrap();
31
32 // Set up the descriptor of an empty directory
33 let b = NewcBuilder::new("./empty_dir")
34 .ino(2)
35 .uid(1000)
36 .gid(1000)
37 .mode(0o000755)
38 .set_mode_file_type(cpio::newc::ModeFileType::Directory);
39 let writer = b.write(output, 0);
40 let output = writer.finish().unwrap();
41
42 // Set up the descriptor of our second input file
43 let b = NewcBuilder::new("./hello_world2")
44 .ino(3)
45 .uid(1000)
46 .gid(1000)
47 .mode(0o100644);
48 // and get a writer for that input file
49 let mut writer = b.write(output, length2);
50
51 // Copy the second input file into our CPIO archive
52 io::copy(&mut input2, &mut writer).unwrap();
53 let output = writer.finish().unwrap();
54
55 let data: &[u8] = b"./hello_world2";
56 let length = data.len() as u32;
57 let mut input = io::Cursor::new(data);
58
59 // Set up the descriptor for a symlink
60 let b = NewcBuilder::new("./hello-link")
61 .ino(4)
62 .uid(1000)
63 .gid(1000)
64 .mode(0o100644)
65 .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
66 let mut writer = b.write(output, length);
67 io::copy(&mut input, &mut writer).unwrap();
68 let output = writer.finish().unwrap();
69
70 // Finish up by writing the trailer for the archive
71 let _ = trailer(output).unwrap();
72}
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?
6fn main() {
7 // Set up our input files
8 let data1: &[u8] = b"Hello, World";
9 let length1 = data1.len() as u32;
10 let mut input1 = io::Cursor::new(data1);
11
12 let data2: &[u8] = b"Hello, World 2";
13 let length2 = data2.len() as u32;
14 let mut input2 = io::Cursor::new(data2);
15
16 // Set up our output file
17 let output = stdout();
18
19 // Set up the descriptor of our input file
20 let b = NewcBuilder::new("./hello_world")
21 .ino(1)
22 .uid(1000)
23 .gid(1000)
24 .mode(0o100644);
25 // and get a writer for that input file
26 let mut writer = b.write(output, length1);
27
28 // Copy the input file into our CPIO archive
29 io::copy(&mut input1, &mut writer).unwrap();
30 let output = writer.finish().unwrap();
31
32 // Set up the descriptor of an empty directory
33 let b = NewcBuilder::new("./empty_dir")
34 .ino(2)
35 .uid(1000)
36 .gid(1000)
37 .mode(0o000755)
38 .set_mode_file_type(cpio::newc::ModeFileType::Directory);
39 let writer = b.write(output, 0);
40 let output = writer.finish().unwrap();
41
42 // Set up the descriptor of our second input file
43 let b = NewcBuilder::new("./hello_world2")
44 .ino(3)
45 .uid(1000)
46 .gid(1000)
47 .mode(0o100644);
48 // and get a writer for that input file
49 let mut writer = b.write(output, length2);
50
51 // Copy the second input file into our CPIO archive
52 io::copy(&mut input2, &mut writer).unwrap();
53 let output = writer.finish().unwrap();
54
55 let data: &[u8] = b"./hello_world2";
56 let length = data.len() as u32;
57 let mut input = io::Cursor::new(data);
58
59 // Set up the descriptor for a symlink
60 let b = NewcBuilder::new("./hello-link")
61 .ino(4)
62 .uid(1000)
63 .gid(1000)
64 .mode(0o100644)
65 .set_mode_file_type(cpio::newc::ModeFileType::Symlink);
66 let mut writer = b.write(output, length);
67 io::copy(&mut input, &mut writer).unwrap();
68 let output = writer.finish().unwrap();
69
70 // Finish up by writing the trailer for the archive
71 let _ = trailer(output).unwrap();
72}