# System.IO.Packaging

**Kind:** Service

**Source:** `Pams/Core/Pams.Core/Pams.Core.csproj` (line 1)

**Part of:** [Pams](subsystem-pams)

NuGet package dependency

`System.IO.Packaging` is a NuGet package dependency referenced by `Pams.Core`. It provides APIs for reading and writing legacy package-format files, allowing core services to access package parts, relationships, and package streams.

## Diagram

```mermaid
sequenceDiagram
    participant Client as TypeScript Client
    participant Core as Pams.Core
    participant Packaging as System.IO.Packaging
    participant File as Legacy Package File

    Client->>Core: Request package processing
    Core->>Packaging: Open package stream
    Packaging->>File: Read package parts and relationships
    File-->>Packaging: Package content
    Packaging-->>Core: Package data
    Core-->>Client: Processing result
```

## Usage

```ts
async function processPackage(file: File) {
  const response = await fetch("/api/packages/process", {
    method: "POST",
    headers: {
      "Content-Type": file.type || "application/octet-stream",
    },
    body: file,
  });

  if (!response.ok) {
    throw new Error("Package processing failed");
  }

  return response.json();
}
```

## AI Coding Instructions

- Keep `System.IO.Packaging` usage inside `Pams.Core` or another .NET service layer; TypeScript clients should interact through an API boundary.
- Treat package streams as disposable resources and close package objects after reading or writing content.
- Preserve package part URIs and relationship identifiers when updating an existing legacy-format package.
- Check package input for missing parts, invalid relationships, and unsupported content before processing it.
