Thomas 7 månader sedan
förälder
incheckning
7ec3ec3a78
2 ändrade filer med 13 tillägg och 7 borttagningar
  1. 3 3
      src/collection/flowcells.rs
  2. 10 4
      src/io/writers.rs

+ 3 - 3
src/collection/flowcells.rs

@@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize};
 use crate::{
     collection::minknow::{parse_pore_activity_from_reader, parse_throughput_from_reader},
     helpers::{find_files, list_directories},
-    io::{readers::get_gz_reader, writers::get_gz_writer},
+    io::{readers::{get_gz_reader, get_reader}, writers::{get_gz_writer, get_writer}},
 };
 
 use super::minknow::{MinKnowSampleSheet, PoreStateEntry, PoreStateEntryExt, ThroughputEntry};
@@ -160,7 +160,7 @@ impl FlowCells {
             return Ok(());
         }
 
-        let file = get_gz_reader(archive_path)
+        let file = get_reader(archive_path)
             .with_context(|| format!("Failed to open archive file: {archive_path}"))?;
 
         let archived: Vec<FlowCell> = serde_json::from_reader(BufReader::new(file))
@@ -179,7 +179,7 @@ impl FlowCells {
         //     .with_context(|| format!("Failed to open archive file for writing: {archive_path}"))?;
         let tmp_path = format!("/tmp/{}.json.gz", uuid::Uuid::new_v4());
 
-        let mut file = get_gz_writer(&tmp_path, true)
+        let mut file = get_writer(&tmp_path)
             .with_context(|| format!("Failed to open archive file for writing: {archive_path}"))?;
 
 

+ 10 - 4
src/io/writers.rs

@@ -1,6 +1,5 @@
 use std::{
-    fs::{self, File, OpenOptions},
-    path::Path,
+    fs::{self, File, OpenOptions}, io::BufWriter, path::Path
 };
 
 use anyhow::Context;
@@ -18,11 +17,18 @@ pub fn get_gz_writer(path: &str, force: bool) -> anyhow::Result<BGZFWriter<File>
 
     let file = OpenOptions::new()
         .write(true) // Open the file for writing
-        .create_new(true)
-        .truncate(true)
         .open(path)
         .with_context(|| anyhow::anyhow!("failed to open the file: {path}"))?;
 
     info!("Writing into {path}");
     Ok(BGZFWriter::new(file, Compression::default()))
 }
+
+pub fn get_writer(path: &str) -> anyhow::Result<BufWriter<File>> {
+    let file = OpenOptions::new()
+        .open(path)
+        .with_context(|| anyhow::anyhow!("failed to open the file: {path}"))?;
+
+    info!("Writing into {path}");
+    Ok(BufWriter::new(file))
+}