Skip to content

Persist and remove a document

This operation covers Document's file-system write and delete lifecycle, including the destructive cascade from Dispose().

Field Value
Operation ID OP-10
Trigger Caller invokes Document.Save(string destinationDirectory), Document.Delete(), or Document.Dispose()
Inputs Destination directory (Save), or none (Delete/Dispose)
Outputs File written to disk, or file removed; true/false from Delete
Primary components PdfAPI.Core.Document.Save, Document.Delete, Document.Dispose
Entry point PdfAPI.Core\Document.cs

Steps

  1. Save: set FilePath to {destinationDirectory}\{FileName} and write all bytes to that path. (BR-22)
  2. Save composes the path with a hard-coded \ separator rather than Path.Combine.*
  3. Delete: delete FilePath when it exists and return true; swallow any exception and return false. (BR-23)
  4. Dispose: call Delete(), so disposing a document removes its file from disk. (BR-24)

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    SaveStart(["Save(destinationDirectory)"]) --> SetPath["FilePath = dir\FileName"]
    SetPath --> Write["Write all bytes"]
    Write --> SaveDone([File persisted])

    DeleteStart(["Delete()"]) --> Exists{FilePath exists?}
    Exists -->|Yes| Del["File.Delete"]
    Del --> True([Return true])
    Exists -->|No| False1([Return false])

    DisposeStart(["Dispose()"]) --> CallDelete["Call Delete()"]
    CallDelete --> DisposeDone([File removed])

Failure and edge-case behavior

  • Any exception during deletion (e.g., file locked, permission denied) is swallowed and reported as false with no diagnostic (BR-23).
  • Disposing a Document obtained from a caller-owned source file destroys that file, since Dispose() unconditionally deletes it (BR-24).

Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.

Sources

  • PdfAPI.Core\Document.cs