Expand description
§Summary
Library to manipulate Nix Archive (nar) files.
For the NAR specification, see “The Purely Functional Deployment Model” by Eelco Dolstra, Figure 5.2 (page 93).
§Encoding
To encode a directory as a NAR file, first create an Encoder
with Encoder::new
, then treat it as a std::io::Read
instance. For instance, you can std::io::copy
it to a file.
use nix_nar::Encoder;
let mut enc = Encoder::new("some/dir").unwrap();
let mut nar = File::create("output.nar")?;
io::copy(&mut enc, &mut nar)?;
If you have very long filenames, use Encoder::builder()
and
then configure the internal buffer size to be at least 200 bytes
larger than the longest filename.
Alternatively, use the Encoder::pack
helper.
§Decoding
To decode a NAR file, first create a Decoder
with
Decoder::new
, and then call Decoder::entries
to iterate
through the files in the archive.
use nix_nar::Decoder;
let input = include_bytes!("../test-data/02-empty-file.nar");
let dec = Decoder::new(&input[..])?;
for entry in dec.entries()? {
let entry = entry?;
println!("{:?} {:?}", entry.path, entry.content);
}
Alternatively, use Decoder::unpack
to extract a NAR file to a
directory.
Modules§
- debug
- Debugging utilities.
Structs§
- Decoder
- Decoder that can extract the contents of NAR files.
- Encoder
- Encoder which can archive a given path as a NAR file.
- Encoder
Builder - Builder for
Encoder
. - Entries
- Iterator over the entries in the archive.
- Entry
- A single entry in a NAR file.