4个版本 (2个重大更新)

0.3.0 2023年8月2日
0.2.1 2023年1月13日
0.2.0 2022年5月4日
0.1.0 2022年4月6日

#900解析器实现

Download history 354/week @ 2024-04-22 621/week @ 2024-04-29 832/week @ 2024-05-06 674/week @ 2024-05-13 600/week @ 2024-05-20 799/week @ 2024-05-27 1083/week @ 2024-06-03 1646/week @ 2024-06-10 771/week @ 2024-06-17 1382/week @ 2024-06-24 850/week @ 2024-07-01 1473/week @ 2024-07-08 1455/week @ 2024-07-15 1876/week @ 2024-07-22 1843/week @ 2024-07-29 1254/week @ 2024-08-05

每月下载量6,443
4 个crate中使用(直接使用2个)

Apache-2.0 OR LGPL-2.1-or-later

51KB
1K SLoC

nix-nar-rs

用于操作Nix存档(nar)文件的库和二进制文件

库使用

有关详细信息,请参阅文档

编码

要将目录编码为NAR文件,首先使用Encoder::new创建一个Encoder,然后将其作为std::io::Read实例处理。例如,您可以将其std::io::copy到文件中。

use nix_nar::Encoder;
let mut enc = Encoder::new("some/dir")?;
let mut nar = File::create("output.nar")?;
io::copy(&mut enc, &mut nar)?;

解码

要解码NAR文件,首先使用Decoder::new创建一个Decoder,然后调用Decoder::entries来遍历存档中的文件。

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);
}

限制

仅支持UTF-8可编码的路径。在实际应用中,这不应该是对*nix或Windows应用程序的限制

Windows部分支持——应该可以构建一切。但是,由于Windows与Unix处理符号链接和文件权限的方式不同,在一个平台上创建NAR并在另一个平台上提取它可能不会像您预期的那样工作。

命令行使用

nix-nar 命令行工具尽可能地匹配 nix nar。它有相同的子命令、选项和输出。

错误消息的措辞有一些差异,并且--directory标志对ls子命令不支持(因为在nix nar中我认为它没有合理的语义)。

USAGE:
    nix-nar <SUBCOMMAND>

OPTIONS:
    -h, --help       Print help information
    -V, --version    Print version information

SUBCOMMANDS:
    cat          Print the contents of a file inside a NAR file on stdout
    dump-path    Serialise a path to stdout in NAR format
    help         Print this message or the help of the given subcommand(s)
    ls           Show information about a path inside a NAR file

安装

将以下内容添加到您的Cargo.toml

nix-nar = "0.2"

二进制文件

您可以通过Cargo或nix flake安装二进制文件

$ cargo install nix-nar-cli
$ nix shell gitlab:abstract-binary/nix-nar-rs       # temporarily
$ nix profile add gitlab:abstract-binary/nix-nar-rs # permanently

参考文献

许可证

本软件采用Apache-2.0和LGPL-2.1或更高版本的双许可。

Apache 2.0

Copyright 2022 Alexandru Scvortov

Licensed under the Apache License, Version 2.0 (the "License"); you
may not use this file except in compliance with the License.  You may
obtain a copy of the License at

https://apache.ac.cn/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.  See the License for the specific language governing
permissions and limitations under the License.

GNU通用公共许可证( Lesser General Public License)2.1或更高版本

Copyright (C) 2022 Alexandru Scvortov

This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.

This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.

依赖项

~0.4–1MB
~19K SLoC