Expand description
XML/HTML output sink — port of LaTeXML::Post::Writer.
Two related concerns live here:
- The
Writerpost-processor (last in the chain) that serializes aPostDocumentto itsdestination, handling DOCTYPE removal, TEMPORARY_DOCUMENT_ID cleanup, and HTML vs XML serialization. - Free-standing helpers (
write_output,ensure_parent_dir) used by binary main()s that already have the serialized string in hand (post-processing returns aString) and need to route it to a destination path or stdout. Replaces the duplicatedFile::create + write! + ensure_parent_dirboilerplate that used to live inlatexml_oxide.rs(and the now-retiredlatexmlpost_oxide.rs).
Companion module: crate::pack (the LaTeXML::Post::Pack analog)
handles archive bundling when the destination is a zip.
Structs§
- Made
Dirs - The directories a page render already made: a split run writes thousands of pages into a handful of
directories, and each
create_dir_allis amkdirand astatx(Nasser’s 71,476-page document, #777 FAQ). - Staged
- A private file beside a destination that parallel render workers may share (the CSS, a figure
every page uses): written or converted there, then installed by one rename,
so no reader sees a partial file and no writer touches another’s. Named
.<stem>.tmp.<pid>.<seq>.<ext>(the stem bounded), its extension kept last for converters that read the format from it; registered with the watchdog’s exit sweep, and removed when dropped — after an install too, since a rename onto a hard link of the same file succeeds and leaves both names (POSIXrename(2); a destination an older binary hard-linked to a graphics-cache entry). A name some file already holds — a killed run’s leftover, perhaps a link to a cache entry, or a process with the same pid in another PID namespace sharing the cache — is skipped, never written through. - Writer
- Writer post-processor: serializes document to file.
Enums§
- Output
Format - Output format for the writer.
Functions§
- bounded_
name name, or for a longer one its first 64 bytes and a hash of the whole: every name derived from a destination (its staged file, a stage of that, a converter’s temp) then stays under the 255-byte NAME_MAX, which a figure name of 220 characters or more took them past.- copy_
atomic - Atomically copy
srctodestthrough aStagedfile. Copying a file onto itself is refused: it would only rewrite it, and a caller that then changesdestwould change its source. The copy isdest’s own: a hard link let an edit of one graphics output in place rewrite the cache entry and every other document’s copy (GFXHARDLINK). - ensure_
parent_ dir - Ensure the parent directory of
pathexists, creating it (and any missing ancestors) as needed. No-op whenpathhas no parent or the parent is the current directory. - made_
dir_ count - How many directories
MadeDirs::ensure_parentasked the OS for on this thread (a test seam). - needs_
write - Whether a bundled resource’s embedded bytes are written to
dest: only where it is missing or an empty regular file (#312’s truncated leftover). A non-empty file in place is used as-is, a user’s or an older release’s; a directory still goes to the write and its error. - same_
bytes - Whether
aandbare regular files holding the same bytes. - same_
file - Whether
aandbname the same existing file (by canonical path). A copy onto itself truncates the file: the destination directory on the resource search path made a stale resource its own only match (#312); a plain!=on two spellings (./, relative) misses it. - write_
atomic - Atomically write
bytestodestthrough aStagedfile. - write_
output - Write the serialized output
contenttodestifSome, else to stdout. Creates parent directories as needed. - write_
output_ segments - Like
write_outputbut writes several segments back-to-back without concatenating them into one buffer first. Used for the conversion log, where the core and post-phase segments are each already-allocated and large for real articles — aformat!("{core}{post}")would allocate a third copy of their combined size on the conversion hot path. Segments are written verbatim and in order through a singleBufWriter(one file open/truncate); insert any separators (e.g."\n") as their own segments.