nirs4all.pipeline.storage.io_writer module

Pipeline file writer - handles file I/O within pipeline directories.

class nirs4all.pipeline.storage.io_writer.PipelineWriter(pipeline_dir: Path, save_charts: bool = True)[source]

Bases: object

Writes files within a pipeline directory.

Focused responsibility: File I/O operations for a single pipeline.

get_path() Path[source]

Get the pipeline directory path.

Returns:

Path to pipeline directory

list_files() list[str][source]

List all files in the pipeline directory.

Returns:

List of filenames

save_file(filename: str, content: str, overwrite: bool = True, encoding: str = 'utf-8', warn_on_overwrite: bool = True) Path[source]

Save a text file to the pipeline directory.

Parameters:
  • filename – Name of file to create

  • content – Text content to write

  • overwrite – Whether to overwrite existing files

  • encoding – Text encoding (default: utf-8)

  • warn_on_overwrite – Whether to warn when overwriting

Returns:

Path to saved file

Raises:

FileExistsError – If file exists and overwrite=False

save_json(filename: str, data: Any, overwrite: bool = True, indent: int | None = 2) Path[source]

Save data as JSON file.

Parameters:
  • filename – Name of file (will add .json if missing)

  • data – Data to serialize as JSON

  • overwrite – Whether to overwrite existing files

  • indent – JSON indentation (None for compact)

Returns:

Path to saved file

save_output(name: str, data: bytes | str, extension: str = '.png') Path | None[source]

Save a human-readable output file (chart, report, etc.).

Parameters:
  • name – Output name (e.g., “2D_Chart”)

  • data – Binary or text data to save

  • extension – File extension (e.g., “.png”, “.csv”, “.txt”)

Returns:

Path to saved file, or None if save_charts=False