Skip to content

Commit

Permalink
💥 Dependency reversal (#369) Dependency reversal `portable-network-ar…
Browse files Browse the repository at this point in the history
…chive` depends on `pna`

* 💥 Dependency reversal `portable-network-archive` depends on `pna`

* 📝 Update README.md
  • Loading branch information
ChanTsune authored Jan 5, 2024
1 parent d73fc73 commit df9e0f0
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 61 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,20 @@ pna --help
## Specification

For more detailed information, please refer to the [Specification](./Specification.md) document.

# License

This project is licensed under either of

* Apache License, Version 2.0, ([LICENSE-APACHE](./LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](./LICENSE-MIT) or
http://opensource.org/licenses/MIT)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this project by you, as defined in the Apache-2.0 license,
shall be dual licensed as above, without any additional terms or conditions.
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ chrono = "0.4.31"
clap = { version = "4.4.11", features = ["derive"] }
glob = "0.3.1"
indicatif = { version = "0.17.7", features = ["improved_unicode"] }
libpna = { version = "0.5.0", path = "../lib" }
pna = { version = "0.5.0", path = "../pna" }
rayon = "1.8.0"
rpassword = "7.3.1"

Expand Down
65 changes: 65 additions & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Portable Network Archive

PNA (Portable Network Archive) is a highly scalable archive format that can be compressed, encrypted, and split.
Also, its data structure is inspired by the PNG data structure.

## Installation

### Via Cargo

```sh
cargo install portable-network-archive
```

### From Source (via Cargo)

```sh
git clone https://github.com/ChanTsune/Portable-Network-Archive.git
```

```sh
cargo install --path cli
```

## Usage

### Creating an Archive

```sh
pna create <ARCHIVE> [FILES]...
```

### Extracting an Archive

```sh
pna extract <ARCHIVE>
```

### Listing Archived Entries

```sh
pna list <ARCHIVE>
```

Use the following command to get help.

```sh
pna --help
```

# License

This project is licensed under either of

* Apache License, Version 2.0, ([LICENSE-APACHE](../LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](../LICENSE-MIT) or
http://opensource.org/licenses/MIT)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this project by you, as defined in the Apache-2.0 license,
shall be dual licensed as above, without any additional terms or conditions.
33 changes: 15 additions & 18 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,23 @@ pub(crate) struct CompressionAlgorithmArgs {
}

impl CompressionAlgorithmArgs {
pub(crate) fn algorithm(&self) -> (libpna::Compression, Option<libpna::CompressionLevel>) {
pub(crate) fn algorithm(&self) -> (pna::Compression, Option<pna::CompressionLevel>) {
if self.store {
(libpna::Compression::No, None)
(pna::Compression::No, None)
} else if let Some(level) = self.xz {
(
libpna::Compression::XZ,
level.map(libpna::CompressionLevel::from),
)
(pna::Compression::XZ, level.map(pna::CompressionLevel::from))
} else if let Some(level) = self.zstd {
(
libpna::Compression::ZStandard,
level.map(libpna::CompressionLevel::from),
pna::Compression::ZStandard,
level.map(pna::CompressionLevel::from),
)
} else if let Some(level) = self.deflate {
(
libpna::Compression::Deflate,
level.map(libpna::CompressionLevel::from),
pna::Compression::Deflate,
level.map(pna::CompressionLevel::from),
)
} else {
(libpna::Compression::ZStandard, None)
(pna::Compression::ZStandard, None)
}
}
}
Expand All @@ -223,23 +220,23 @@ pub(crate) struct CipherAlgorithmArgs {
}

impl CipherAlgorithmArgs {
pub(crate) fn algorithm(&self) -> libpna::Encryption {
pub(crate) fn algorithm(&self) -> pna::Encryption {
if self.aes.is_some() {
libpna::Encryption::Aes
pna::Encryption::Aes
} else if self.camellia.is_some() {
libpna::Encryption::Camellia
pna::Encryption::Camellia
} else {
libpna::Encryption::Aes
pna::Encryption::Aes
}
}

pub(crate) fn mode(&self) -> libpna::CipherMode {
pub(crate) fn mode(&self) -> pna::CipherMode {
match match (self.aes, self.camellia) {
(Some(mode), _) | (_, Some(mode)) => mode.unwrap_or_default(),
(None, None) => CipherMode::default(),
} {
CipherMode::Cbc => libpna::CipherMode::CBC,
CipherMode::Ctr => libpna::CipherMode::CTR,
CipherMode::Cbc => pna::CipherMode::CBC,
CipherMode::Ctr => pna::CipherMode::CTR,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/command/append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
Command,
},
};
use libpna::Archive;
use pna::Archive;
use rayon::ThreadPoolBuilder;
use std::{fs::File, io};

Expand Down
8 changes: 4 additions & 4 deletions cli/src/command/commons.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::cli::{CipherAlgorithmArgs, CompressionAlgorithmArgs};
use libpna::{
EntryBuilder, EntryName, EntryPart, EntryReference, Permission, RegularEntry, WriteOption,
};
#[cfg(unix)]
use nix::unistd::{Group, User};
use pna::{
EntryBuilder, EntryName, EntryPart, EntryReference, Permission, RegularEntry, WriteOption,
};
#[cfg(unix)]
use std::os::unix::fs::{MetadataExt, PermissionsExt};
use std::{
Expand Down Expand Up @@ -87,7 +87,7 @@ pub(crate) fn entry_option(
.encryption(if password.is_some() {
cipher.algorithm()
} else {
libpna::Encryption::No
pna::Encryption::No
})
.cipher_mode(cipher.mode())
.password(password);
Expand Down
4 changes: 1 addition & 3 deletions cli/src/command/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ use crate::{
};
use bytesize::ByteSize;
use indicatif::{HumanDuration, ProgressBar, ProgressStyle};
use libpna::{
Archive, EntryPart, SolidEntryBuilder, WriteOption, MIN_CHUNK_BYTES_SIZE, PNA_HEADER,
};
use pna::{Archive, EntryPart, SolidEntryBuilder, WriteOption, MIN_CHUNK_BYTES_SIZE, PNA_HEADER};
use rayon::ThreadPoolBuilder;
use std::{
fs::{self, File},
Expand Down
2 changes: 1 addition & 1 deletion cli/src/command/experimental.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
};
use bytesize::ByteSize;
use clap::{Args, Parser, Subcommand};
use libpna::{Archive, EntryPart, MIN_CHUNK_BYTES_SIZE, PNA_HEADER};
use pna::{Archive, EntryPart, MIN_CHUNK_BYTES_SIZE, PNA_HEADER};
use std::{fs::File, io, path::PathBuf};

#[derive(Args, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion cli/src/command/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use crate::{
};
use glob::Pattern;
use indicatif::{HumanDuration, ProgressBar, ProgressStyle};
use libpna::{Archive, DataKind, Permission, ReadOption, RegularEntry};
#[cfg(unix)]
use nix::unistd::{chown, Group, User};
use pna::{Archive, DataKind, Permission, ReadOption, RegularEntry};
use rayon::{prelude::*, ThreadPoolBuilder};
use std::ops::Add;
#[cfg(target_os = "macos")]
Expand Down
2 changes: 1 addition & 1 deletion cli/src/command/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
use ansi_term::{ANSIString, Colour, Style};
use chrono::{DateTime, Local};
use glob::Pattern;
use libpna::{Archive, Compression, DataKind, Encryption, ReadOption, RegularEntry};
use pna::{Archive, Compression, DataKind, Encryption, ReadOption, RegularEntry};
use rayon::prelude::*;
use std::{
fs::File,
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/hardlink.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Parser;
use libpna::{Archive, EntryBuilder, EntryName, EntryReference, WriteOption};
use pna::{Archive, EntryBuilder, EntryName, EntryReference, WriteOption};
use portable_network_archive::{cli, command};
use std::{fs, io::Write, path::Path};

Expand Down
5 changes: 2 additions & 3 deletions lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ A pna archive reading/writing library for Rust.
```toml
# Cargo.toml
[dependencies]
libpna = "0.3"
libpna = "0.5"
```

## Reading an archive

```rust
use libpna::Archive;
use libpna::{Archive, ReadOption};
use std::fs::File;
use std::io::{self, copy, prelude::*};

fn main() -> io::Result<()> {
use libpna::ReadOption;
let file = File::open("foo.pna")?;
let mut archive = Archive::read_header(file)?;
for entry in archive.entries() {
Expand Down
9 changes: 0 additions & 9 deletions pna/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ keywords = ["pna", "archive", "crypto", "data"]

[dependencies]
libpna = { version = "0.5.0", path = "../lib" }
portable-network-archive = { version = "0.5.0", path = "../cli", optional = true }

[lib]
name = "pna"

[features]
cli = ["portable-network-archive"]

[[bin]]
name = "pna"
path = "src/bin/pna.rs"
required-features = ["cli"]
90 changes: 80 additions & 10 deletions pna/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,92 @@
# Portable-Network-Archive
# pna
[![test](https://github.com/ChanTsune/Portable-Network-Archive/actions/workflows/test.yml/badge.svg)](https://github.com/ChanTsune/Portable-Network-Archive/actions/workflows/test.yml)
[![Crates.io][crates-badge]][crates-url]

Portable-Network-Archive (PNA)
Highly scalable archive format inspired by the PNG data structure with file compression, splitting and encryption.
[crates-badge]: https://img.shields.io/crates/v/pna.svg
[crates-url]: https://crates.io/crates/pna

## Installation
A pna archive reading/writing library for Rust.

```toml
# Cargo.toml
[dependencies]
pna = "0.5"
```

## Reading an archive

```rust
use pna::{Archive, ReadOption};
use std::fs::File;
use std::io::{self, copy, prelude::*};

fn main() -> io::Result<()> {
let file = File::open("foo.pna")?;
let mut archive = Archive::read_header(file)?;
for entry in archive.entries() {
let entry = entry?;
let mut file = File::create(entry.header().path().as_path())?;
let mut reader = entry.reader(ReadOption::builder().build())?;
copy(&mut reader, &mut file)?;
}
Ok(())
}
```

## Writing an archive

```rust
use pna::{Archive, EntryBuilder, WriteOption};
use std::fs::File;
use std::io::{self, prelude::*};

fn main() -> io::Result<()> {
let file = File::create("foo.pna")?;
let mut archive = Archive::write_header(file)?;
let mut entry_builder = EntryBuilder::new_file(
"bar.txt".try_into().unwrap(),
WriteOption::builder().build(),
)?;
entry_builder.write(b"content")?;
let entry = entry_builder.build()?;
archive.add_entry(entry)?;
archive.finalize()?;
Ok(())
}
```

# CLI
Command line user interface are available and you can install via cargo or build from source.

### Via Cargo

```sh
cargo install pna --features cli
cargo install portable-network-archive
```

## Usage
### From Source (via Cargo)

Use the following command to get help.
```sh
git clone https://github.com/ChanTsune/Portable-Network-Archive.git
```

```sh
pna --help
cargo install --path cli
```

## Specification
# License

This project is licensed under either of

* Apache License, Version 2.0, ([LICENSE-APACHE](../LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](../LICENSE-MIT) or
http://opensource.org/licenses/MIT)

at your option.

### Contribution

For more detail read [Specification](../Specification.md)
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this project by you, as defined in the Apache-2.0 license,
shall be dual licensed as above, without any additional terms or conditions.
Loading

0 comments on commit df9e0f0

Please sign in to comment.