diff --git a/Cargo.toml b/Cargo.toml index 99b6c5b..1a7b663 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,6 @@ spki = { version = "0.8.0", default-features = false, features = [ "pem", "std", ] } -zip = "8.5.1" [build-dependencies] napi-build = "2.3.1" diff --git a/README.md b/README.md index 0441918..a9f4dd3 100644 --- a/README.md +++ b/README.md @@ -10,5 +10,3 @@ An internal library for Misskey backend used to obtain performance benefits. - aws-lc-sys - `Signer` (requires init before use) - `Verifier` (requires init before use) -- zip - - `ZipReader` diff --git a/index.d.ts b/index.d.ts index e38537c..8893d4e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -23,12 +23,6 @@ export declare class Verifier { } export type JsVerifier = Verifier -export declare class ZipReader { - static withDestinationPath(path: string): ZipReader - viaBuffer(buffer: Buffer): void -} -export type JsZipReader = ZipReader - export declare function init(numThreads: number): void export declare const enum SignatureAlgorithmIdentifier { diff --git a/index.js b/index.js index 3fbbc1f..63a7bea 100644 --- a/index.js +++ b/index.js @@ -582,7 +582,5 @@ module.exports.Signer = nativeBinding.Signer module.exports.JsSigner = nativeBinding.JsSigner module.exports.Verifier = nativeBinding.Verifier module.exports.JsVerifier = nativeBinding.JsVerifier -module.exports.ZipReader = nativeBinding.ZipReader -module.exports.JsZipReader = nativeBinding.JsZipReader module.exports.init = nativeBinding.init module.exports.SignatureAlgorithmIdentifier = nativeBinding.SignatureAlgorithmIdentifier diff --git a/src/lib.rs b/src/lib.rs index a40f827..f20c91e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,6 @@ extern crate napi_derive; pub mod aho_corasick; pub mod aws_lc_rs; -pub mod zip; pub(crate) static THREAD_POOL: OnceLock = OnceLock::new(); diff --git a/src/zip.rs b/src/zip.rs deleted file mode 100644 index 5dd04c0..0000000 --- a/src/zip.rs +++ /dev/null @@ -1,53 +0,0 @@ -use std::{ - io::Cursor, - path::{Path, PathBuf}, -}; - -use napi::bindgen_prelude::*; -use zip; - -pub struct ZipReader {} - -#[napi(js_name = "ZipReader")] -pub struct JsZipReader { - destination: DestinationType, -} - -enum DestinationType { - Path(Box), -} - -#[napi] -impl JsZipReader { - #[napi(factory)] - pub fn with_destination_path(path: String) -> Self { - Self { - destination: DestinationType::Path(PathBuf::from(&path).into_boxed_path()), - } - } - - #[napi] - pub fn via_buffer(&self, buffer: Buffer) -> Result<()> { - let mut zip = zip::ZipArchive::new(Cursor::new(buffer.as_ref())).map_err(|err| { - Error::new( - Status::InvalidArg, - format!("Failed to open zip archive: {}", err), - ) - })?; - self.extract(&mut zip) - } - - fn extract(&self, zip: &mut zip::ZipArchive>) -> Result<()> { - match &self.destination { - DestinationType::Path(path) => { - zip.extract(path).map_err(|err| { - Error::new( - Status::InvalidArg, - format!("Failed to extract zip archive: {}", err), - ) - })?; - } - } - Ok(()) - } -} diff --git a/test/resources/zip/sqlite-amalgamation-3410200.zip b/test/resources/zip/sqlite-amalgamation-3410200.zip deleted file mode 100644 index 2697b87..0000000 Binary files a/test/resources/zip/sqlite-amalgamation-3410200.zip and /dev/null differ diff --git a/test/zip.test.mjs b/test/zip.test.mjs deleted file mode 100644 index 65814dc..0000000 --- a/test/zip.test.mjs +++ /dev/null @@ -1,58 +0,0 @@ -import * as crypto from "node:crypto"; -import * as fs from "node:fs/promises"; -import * as path from "node:path"; -import { describe, expect, it } from "vitest"; -import { ZipReader } from "../index.js"; - -describe(ZipReader.name, () => { - it("should read zip file", async () => { - await fs.mkdir(path.resolve(__dirname, "..", "node_modules", ".tmp"), { - recursive: true, - }); - const tmp = await fs.mkdtemp( - path.resolve(__dirname, "..", "node_modules", ".tmp", "zip-") - ); - try { - const zip = ZipReader.withDestinationPath(tmp); - zip.viaBuffer( - await fs.readFile( - path.resolve( - __dirname, - "resources", - "zip", - "sqlite-amalgamation-3410200.zip" - ) - ) - ); - const files = await fs.readdir( - path.resolve(tmp, "sqlite-amalgamation-3410200") - ); - expect(files).toEqual([ - "shell.c", - "sqlite3.c", - "sqlite3.h", - "sqlite3ext.h", - ]); - const hashes = await Promise.all( - files.map(async (file) => - crypto - .createHash("sha256") - .update( - await fs.readFile( - path.resolve(tmp, "sqlite-amalgamation-3410200", file) - ) - ) - .digest("hex") - ) - ); - expect(hashes).toEqual([ - "917bb6d7539c2a782bfbfcdec2405a7a27070930ada28ae00607fe1e9b3f3ad1", - "efe007ec6f1a4084b87cebba18cc887c316e0baaf4ec2675990726b94cb85470", - "10ff8c8842b5e6bb0555f39ce946b77d0f84acc9e33895d22242444d91900571", - "cf9785762f8801049b841f873cdeecfa2780b0f6465e2b76f72d2c10384cf7ce", - ]); - } finally { - await fs.rm(tmp, { recursive: true }); - } - }); -});