From 445fb62f8bf7a5fd22214a313d7283da8e56c03e Mon Sep 17 00:00:00 2001 From: AkiyukiOkayasu Date: Wed, 21 Aug 2024 14:48:14 +0900 Subject: [PATCH] Simplify download function --- Cargo.toml | 1 - tests/integration_test.rs | 23 ++++++++--------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2c016f8..fadc873 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,6 @@ reqwest = { version = "0.12.7", features = ["blocking"] } cpal = "0.15.3" approx = "0.5.1" criterion = "0.4.0" -tempfile = "3.12.0" [[bench]] name = "bench" diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 96f9cb7..16f1963 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -4,8 +4,6 @@ use pacmog::{ AudioFormat, PcmPlayer, PcmReaderBuilder, }; use reqwest::blocking::get; -use std::io::{self, Read, Write}; -use tempfile::NamedTempFile; const SINEWAVE: [f32; 3000] = [ 0f32, @@ -3010,6 +3008,12 @@ const SINEWAVE: [f32; 3000] = [ 0.05130394f32, ]; +fn download_audio_file(url: &str) -> Result, reqwest::Error> { + let response = get(url)?; + let bytes = response.bytes()?; + Ok(bytes.to_vec()) +} + #[test] fn fixed_test() { let hoge = I1F15::from_num(0.5); @@ -3053,19 +3057,10 @@ fn aiff_linearpcm_specs() { } #[test] -fn wav_float32_specs() -> io::Result<()> { +fn wav_float32_specs() { // Download the wave file using reqwest let url = "https://github.com/AkiyukiOkayasu/TestToneSet/raw/main/Sine440Hz_1ch48000HzFP32.wav"; - let response = get(url).expect("Failed to download file"); - let content = response.bytes().expect("Failed to read response bytes"); - - // Create a temporary file - let mut temp_file = NamedTempFile::new()?; - temp_file.write_all(&content)?; - - // Read the downloaded file into a byte array - let mut wav = Vec::new(); - temp_file.reopen()?.read_to_end(&mut wav)?; + let wav = download_audio_file(url).unwrap(); // Use PcmReaderBuilder to read the PCM specs let reader = PcmReaderBuilder::new(&wav).build().unwrap(); @@ -3077,8 +3072,6 @@ fn wav_float32_specs() -> io::Result<()> { assert_eq!(spec.num_channels, 1); assert_eq!(spec.sample_rate, 48000); assert_eq!(spec.num_samples, 240000); - - Ok(()) } #[test]