migrate to zstd

This commit is contained in:
DecDuck
2024-10-07 13:21:16 +11:00
parent fe50bcc2da
commit 50c2c0ea3f
3 changed files with 6 additions and 7 deletions
+2 -1
View File
@@ -196,4 +196,5 @@ Cargo.lock
*.node
index.js
index.d.ts
index.d.ts
test.mjs
+1 -1
View File
@@ -10,7 +10,7 @@ crate-type = ["cdylib"]
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
napi = { version = "2.12.2", default-features = false, features = ["napi4", "async"] }
napi-derive = "2.12.2"
xz2 = "0.1.7"
zstd = "0.13.2"
rayon = "1.10.0"
serde = "1.0.210"
ciborium = "0.2.2"
+3 -5
View File
@@ -8,13 +8,12 @@ use napi::Error;
use std::{
collections::HashMap,
fs::File,
io::{self, BufRead, BufReader},
io::{BufRead, BufReader},
os::unix::fs::PermissionsExt,
path::Path,
sync::{Arc, Mutex},
};
use uuid::Uuid;
use xz2::bufread::XzEncoder;
pub mod file_utils;
pub mod manifest;
@@ -24,10 +23,9 @@ extern crate napi_derive;
fn compress(buffer: &[u8], output_path: &Path, chunk_id: Uuid) {
let chunk_path = output_path.join(chunk_id.to_string() + ".bin");
let mut chunk_file = File::create(chunk_path).unwrap();
let mut compressor: XzEncoder<&[u8]> = XzEncoder::new(&buffer[..], 6);
let chunk_file = File::create_new(chunk_path).unwrap();
io::copy(&mut compressor, &mut chunk_file).unwrap();
zstd::stream::copy_encode(buffer, chunk_file, 9).unwrap();
}
#[napi]