Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0f6a51e

Browse filesBrowse files
Merge pull request theseus-rs#89 from theseus-rs/remove-bytes-dependency
refactor!: remove bytes dependency
2 parents cc78897 + f8bd4b0 commit 0f6a51e
Copy full SHA for 0f6a51e

File tree

Expand file treeCollapse file tree

10 files changed

+42
-79
lines changed
Filter options
Expand file treeCollapse file tree

10 files changed

+42
-79
lines changed

‎Cargo.lock

Copy file name to clipboardExpand all lines: Cargo.lock
-2Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

Copy file name to clipboardExpand all lines: Cargo.toml
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ version = "0.12.0"
2525
anyhow = "1.0.86"
2626
async-trait = "0.1.80"
2727
blake2 = "0.10.6"
28-
bytes = "1.6.0"
2928
criterion = "0.5.1"
3029
flate2 = "1.0.30"
3130
hex = "0.4.3"

‎postgresql_archive/Cargo.toml

Copy file name to clipboardExpand all lines: postgresql_archive/Cargo.toml
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ version.workspace = true
1313
anyhow = { workspace = true }
1414
async-trait = { workspace = true }
1515
blake2 = { workspace = true }
16-
bytes = { workspace = true }
1716
flate2 = { workspace = true }
1817
hex = { workspace = true }
1918
http = { workspace = true }

‎postgresql_archive/benches/archive.rs

Copy file name to clipboardExpand all lines: postgresql_archive/benches/archive.rs
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use bytes::Bytes;
21
use criterion::{criterion_group, criterion_main, Criterion};
32
use postgresql_archive::blocking::{extract, get_archive};
43
use postgresql_archive::{Result, VersionReq, DEFAULT_POSTGRESQL_URL};
@@ -22,7 +21,7 @@ fn bench_extract(criterion: &mut Criterion) -> Result<()> {
2221
Ok(())
2322
}
2423

25-
fn extract_archive(archive: &Bytes) -> Result<()> {
24+
fn extract_archive(archive: &Vec<u8>) -> Result<()> {
2625
let out_dir = tempfile::tempdir()?.path().to_path_buf();
2726
create_dir_all(&out_dir)?;
2827
extract(archive, &out_dir)?;

‎postgresql_archive/src/archive.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/archive.rs
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use crate::error::Error::Unexpected;
55
use crate::error::Result;
66
use crate::repository;
7-
use bytes::Bytes;
87
use flate2::bufread::GzDecoder;
98
use human_bytes::human_bytes;
109
use num_format::{Locale, ToFormattedString};
@@ -39,12 +38,11 @@ pub async fn get_version(url: &str, version_req: &VersionReq) -> Result<Version>
3938
/// * If the archive is not found.
4039
/// * If the archive cannot be downloaded.
4140
#[instrument]
42-
pub async fn get_archive(url: &str, version_req: &VersionReq) -> Result<(Version, Bytes)> {
41+
pub async fn get_archive(url: &str, version_req: &VersionReq) -> Result<(Version, Vec<u8>)> {
4342
let repository = repository::registry::get(url)?;
4443
let archive = repository.get_archive(version_req).await?;
4544
let version = archive.version().clone();
46-
let archive_bytes = archive.bytes().to_vec();
47-
let bytes = Bytes::from(archive_bytes.clone());
45+
let bytes = archive.bytes().to_vec();
4846
Ok((version, bytes))
4947
}
5048

@@ -97,13 +95,13 @@ fn acquire_lock(out_dir: &Path) -> Result<PathBuf> {
9795
Err(Unexpected("Failed to acquire lock".to_string()))
9896
}
9997

100-
/// Extracts the compressed tar [bytes](Bytes) to the [out_dir](Path).
98+
/// Extracts the compressed tar `bytes` to the [out_dir](Path).
10199
///
102100
/// # Errors
103101
/// Returns an error if the extraction fails.
104102
#[allow(clippy::cast_precision_loss)]
105103
#[instrument(skip(bytes))]
106-
pub async fn extract(bytes: &Bytes, out_dir: &Path) -> Result<()> {
104+
pub async fn extract(bytes: &Vec<u8>, out_dir: &Path) -> Result<()> {
107105
let input = BufReader::new(Cursor::new(bytes));
108106
let decoder = GzDecoder::new(input);
109107
let mut archive = Archive::new(decoder);

‎postgresql_archive/src/blocking/archive.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/blocking/archive.rs
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::{Version, VersionReq};
2-
use bytes::Bytes;
32
use std::path::Path;
43
use tokio::runtime::Runtime;
54

@@ -25,17 +24,17 @@ pub fn get_version(url: &str, version_req: &VersionReq) -> crate::Result<Version
2524
/// # Errors
2625
/// * If the archive is not found.
2726
/// * If the archive cannot be downloaded.
28-
pub fn get_archive(url: &str, version_req: &VersionReq) -> crate::Result<(Version, Bytes)> {
27+
pub fn get_archive(url: &str, version_req: &VersionReq) -> crate::Result<(Version, Vec<u8>)> {
2928
RUNTIME
3029
.handle()
3130
.block_on(async move { crate::get_archive(url, version_req).await })
3231
}
3332

34-
/// Extracts the compressed tar [bytes](Bytes) to the [out_dir](Path).
33+
/// Extracts the compressed tar `bytes` to the [out_dir](Path).
3534
///
3635
/// # Errors
3736
/// Returns an error if the extraction fails.
38-
pub fn extract(bytes: &Bytes, out_dir: &Path) -> crate::Result<()> {
37+
pub fn extract(bytes: &Vec<u8>, out_dir: &Path) -> crate::Result<()> {
3938
RUNTIME
4039
.handle()
4140
.block_on(async move { crate::extract(bytes, out_dir).await })

‎postgresql_archive/src/hasher/registry.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/hasher/registry.rs
+32-59Lines changed: 32 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ pub fn get<S: AsRef<str>>(extension: S) -> Option<HasherFn> {
8181
mod tests {
8282
use super::*;
8383

84+
fn test_hasher(extension: &str, expected: &str) -> Result<()> {
85+
let hasher = get(extension).unwrap();
86+
let data = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
87+
let hash = hasher(&data)?;
88+
assert_eq!(expected, hash);
89+
Ok(())
90+
}
91+
8492
#[test]
8593
fn test_register() -> Result<()> {
8694
let extension = "sha256";
@@ -91,92 +99,57 @@ mod tests {
9199
register(extension, sha2_256::hash);
92100
assert_eq!(hashers, REGISTRY.lock().unwrap().hashers.len());
93101

94-
let hasher = get(extension).unwrap();
95-
let data = vec![1, 2, 3];
96-
let hash = hasher(&data)?;
97-
98-
assert_eq!(
99-
"039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81",
100-
hash
101-
);
102-
Ok(())
102+
test_hasher(
103+
extension,
104+
"9a89c68c4c5e28b8c4a5567673d462fff515db46116f9900624d09c474f593fb",
105+
)
103106
}
104107

105108
#[test]
106109
fn test_sha2_256() -> Result<()> {
107-
let hasher = get("sha256").unwrap();
108-
let data = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
109-
let hash = hasher(&data)?;
110-
111-
assert_eq!(
110+
test_hasher(
111+
"sha256",
112112
"9a89c68c4c5e28b8c4a5567673d462fff515db46116f9900624d09c474f593fb",
113-
hash
114-
);
115-
Ok(())
113+
)
116114
}
117115

118116
#[test]
119117
fn test_sha2_512() -> Result<()> {
120-
let hasher = get("sha512").unwrap();
121-
let data = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
122-
let hash = hasher(&data)?;
123-
124-
assert_eq!(
118+
test_hasher(
119+
"sha512",
125120
"3ad3f36979450d4f53366244ecf1010f4f9121d6888285ff14104fd5aded85d48aa171bf1e33a112602f92b7a7088b298789012fb87b9056321241a19fb74e0b",
126-
hash
127-
);
128-
Ok(())
121+
)
129122
}
130123

131124
#[test]
132125
fn test_sha3_256() -> Result<()> {
133-
let hasher = get("sha3-256").unwrap();
134-
let data = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
135-
let hash = hasher(&data)?;
136-
137-
assert_eq!(
126+
test_hasher(
127+
"sha3-256",
138128
"c0188232190e0427fc9cc78597221c76c799528660889bd6ce1f3563148ff84d",
139-
hash
140-
);
141-
Ok(())
129+
)
142130
}
143131

144132
#[test]
145133
fn test_sha3_512() -> Result<()> {
146-
let hasher = get("sha3-512").unwrap();
147-
let data = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
148-
let hash = hasher(&data)?;
149-
150-
assert_eq!(
134+
test_hasher(
135+
"sha3-512",
151136
"9429fc1f9772cc1d8039fe75cc1b033cd60f0ec4face0f8a514d25b0649ba8a5954b6c7a41cc3697a56db3ff321475be1fa14b70c7eb78fec6ce62dbfc54c9d3",
152-
hash
153-
);
154-
Ok(())
137+
)
155138
}
156139

157140
#[test]
158141
fn test_blake2s_256() -> Result<()> {
159-
let hasher = get("blake2s").unwrap();
160-
let data = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
161-
let hash = hasher(&data)?;
162-
163-
assert_eq!(
142+
test_hasher(
143+
"blake2s",
164144
"7125921e06071710350390fe902856dbea366a5d6f5ee26c18e741143ac80061",
165-
hash
166-
);
167-
Ok(())
145+
)
168146
}
169147

170148
#[test]
171-
fn test_blake2s_512() -> Result<()> {
172-
let hasher = get("blake2s").unwrap();
173-
let data = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
174-
let hash = hasher(&data)?;
175-
176-
assert_eq!(
177-
"7125921e06071710350390fe902856dbea366a5d6f5ee26c18e741143ac80061",
178-
hash
179-
);
180-
Ok(())
149+
fn test_blake2b_512() -> Result<()> {
150+
test_hasher(
151+
"blake2b",
152+
"67767f1cab415502dcceec9f099fb84539b1c73c5ebdcfe1bb8ca7411e3b6cb33e304f49222edac9bdaa74129e9e13f11f215b8560f9081f0e8f1f869162bf46",
153+
)
181154
}
182155
}

‎postgresql_archive/src/repository/github/repository.rs

Copy file name to clipboardExpand all lines: postgresql_archive/src/repository/github/repository.rs
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::Error::{
77
};
88
use crate::{hasher, matcher, Result};
99
use async_trait::async_trait;
10-
use bytes::Bytes;
1110
use http::{header, Extensions};
1211
use human_bytes::human_bytes;
1312
use regex::Regex;
@@ -237,7 +236,7 @@ impl Repository for GitHub {
237236
debug!("Downloading archive {}", asset.browser_download_url);
238237
let request = client.get(&asset.browser_download_url);
239238
let response = request.send().await?.error_for_status()?;
240-
let archive: Bytes = response.bytes().await?;
239+
let archive = response.bytes().await?;
241240
let bytes = archive.to_vec();
242241
debug!(
243242
"Archive {} downloaded: {}",

‎postgresql_embedded/Cargo.toml

Copy file name to clipboardExpand all lines: postgresql_embedded/Cargo.toml
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ tokio = { workspace = true, features = ["full"] }
1818

1919
[dependencies]
2020
anyhow = { workspace = true }
21-
bytes = { workspace = true }
2221
home = { workspace = true }
2322
lazy_static = { workspace = true }
2423
postgresql_archive = { path = "../postgresql_archive", version = "0.12.0", default-features = false }

‎postgresql_embedded/src/postgresql.rs

Copy file name to clipboardExpand all lines: postgresql_embedded/src/postgresql.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl PostgreSQL {
157157
debug!("Using bundled installation archive");
158158
(
159159
self.settings.version.clone(),
160-
bytes::Bytes::copy_from_slice(crate::settings::ARCHIVE),
160+
crate::settings::ARCHIVE.to_vec(),
161161
)
162162
} else {
163163
let (version, bytes) =

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.