Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,35 @@ tool under `tools/` keeps its own.

## [Unreleased]

## [v0.14.0] - 2026-12-02

This release narrows what `route.At` reads as text: a head that holds a control byte, or whose
bytes are neither UTF-8 nor windows-1252, is no longer text. `route.MediaType` now types text of no
signature by its name's extension, and a HEIC by its major brand.

### Changed

- **Breaking:** content of no routed signature, or content that fails a claim's own check, is text
only when its first `route.HeadLen` bytes pass two tests. They hold no control byte, meaning no
C0 control other than tab, line feed, form feed, or carriage return, and no DEL. They are also
either valid UTF-8 or windows-1252 without its five undefined bytes, 0x81, 0x8D, 0x8F, 0x90, and
0x9D; a UTF-8 rune cut off at the head's end is allowed when the content runs past the head.
Before, any head without a NUL byte was text. Content with a control byte but no NUL byte, such
as a log holding terminal escapes, and content that is neither UTF-8 nor windows-1252 now routes
`route.Unrouted`, and `route.MediaType` types it application/octet-stream, not text/plain.
Content stored as an audio or video type routes by that type when its head fails the same tests.
A byte order mark still makes content text before the tests run.
- `route.MediaType` types content of no signature that routes `route.Text` by its name's extension,
as `route.Ext` reads it, from a table in the `route` package: text/markdown for .md or .markdown,
text/csv for .csv, text/tab-separated-values for .tsv, text/html for .html or .htm,
application/xml for .xml, application/json for .json, application/yaml for .yaml or .yml, text/css
for .css, text/javascript for .js or .mjs, text/calendar for .ics, and text/vcard for .vcf; any
other extension stays text/plain, as does text marked by a byte order mark or a script's "#!"
line. Content that isn't text stays application/octet-stream whatever its name.
- `route.MediaType` types a `route.HEIC` by its ftyp box's major brand: image/heic for heic, heix,
heim, or heis; image/heic-sequence for hevc or hevx; image/heif for heif, mif1, or miaf; and
image/heif-sequence for msf1. Before, every HEIC was image/heic. Its route is unchanged.

## [v0.13.0] - 2026-12-02

This release adds `route.MediaType`, the media type of content as `route.At` routes it, on `At`'s
Expand Down Expand Up @@ -745,7 +774,8 @@ fixtures scripts stay in the spike.
The [limits page](docs/limits.md) states them: each stage's tool's limits, docproc-ooxml's
behavior under a memory bound, the Threader's memory, and the formats no stage reads.

[Unreleased]: https://github.com/standards-lab/docproc/compare/v0.13.0...HEAD
[Unreleased]: https://github.com/standards-lab/docproc/compare/v0.14.0...HEAD
[v0.14.0]: https://github.com/standards-lab/docproc/compare/v0.13.0...v0.14.0
[v0.13.0]: https://github.com/standards-lab/docproc/compare/v0.12.0...v0.13.0
[v0.12.0]: https://github.com/standards-lab/docproc/compare/v0.11.0...v0.12.0
[v0.11.0]: https://github.com/standards-lab/docproc/compare/v0.10.0...v0.11.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tags.
## Install

```sh
go get github.com/standards-lab/docproc@v0.13.0
go get github.com/standards-lab/docproc@v0.14.0
```

The module's releases are tagged `vX.Y.Z`, and [`CHANGELOG.md`](CHANGELOG.md) states what each
Expand Down
2 changes: 1 addition & 1 deletion cmd/docproc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ postgres modules, and each system tool under `tools/` keep their own.
stays beside its `export_test.go`. The command line, run directory, and exit codes don't change.
- `mise run build` at the repository root writes the docproc command to the git-ignored
`bin/docproc`.
- The module requires the docproc base module at v0.12.0, from v0.11.0, whose
- The module requires the docproc base module at v0.13.0, from v0.11.0, whose
[CHANGELOG](../../CHANGELOG.md) states its changes in full.
- The module requires go-core v0.15.0, from v0.14.0; nothing `docproc run` does changes with it.

Expand Down
2 changes: 1 addition & 1 deletion cmd/docproc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/standards-lab/docproc/cmd/docproc
go 1.27.4

require (
github.com/standards-lab/docproc v0.12.0
github.com/standards-lab/docproc v0.13.0
github.com/standards-lab/go-cli-sdk v0.4.0
github.com/standards-lab/go-core v0.15.0
golang.org/x/sys v0.50.0
Expand Down
4 changes: 2 additions & 2 deletions cmd/docproc/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/standards-lab/docproc v0.12.0 h1:fKof6WCaze3tu+sCI5cx3OgsH5s86Aus65DBsQNA0Mg=
github.com/standards-lab/docproc v0.12.0/go.mod h1:ZA8JYQPooA6YA84b00Lpu5AiSL2VSj/u7QnenltqVBA=
github.com/standards-lab/docproc v0.13.0 h1:WRvUFHvMM1eFxBr9sFkgRH7Co2GkW2jgrEvdflPY6Io=
github.com/standards-lab/docproc v0.13.0/go.mod h1:ZA8JYQPooA6YA84b00Lpu5AiSL2VSj/u7QnenltqVBA=
github.com/standards-lab/go-cli-sdk v0.4.0 h1:232dyKPD5kqshp0BMEVEZaedwJfvnDVqWLv7m1NQWmI=
github.com/standards-lab/go-cli-sdk v0.4.0/go.mod h1:7Y1BCcHtuu8Unxc+Hryjlln+0fbiMYa5xY75aueJ/rY=
github.com/standards-lab/go-core v0.15.0 h1:yYjuUDlI7CupvtHJMT9Db7dAzNug3QJPGAEVruhIJI8=
Expand Down
9 changes: 6 additions & 3 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ func Identify(head []byte) Kind // at most HeadLe
func File(path, name, mimeType string) (Route, string, error) // the route, and why
func At(r io.ReaderAt, size int64, head []byte, name, mimeType string) (Route, string, error)
func MediaType(r io.ReaderAt, size int64, head []byte, name, mimeType string) (string, error)
// a Kind's type, a HEIC's by its major brand; text of no signature by Ext from route's
// table, else text/plain; content that isn't text application/octet-stream
func Ext(name string) string // trimmed and lowercased
func EncryptedPackage(r io.ReaderAt, size int64) (bool, error) // an OLE2 EncryptedPackage
func RARVolume(head []byte) bool // a RAR's main header marks a volume
Expand Down Expand Up @@ -931,9 +933,10 @@ What each stage yields, and why, beside the `Meta` keys `dispatch` documents on
images, embedded files, and ink, is found at `page <id>, media <n>`, named by the name it was
inserted or attached under, else by its media name; one with no content written, its data missing
or invalid, is a failed child. A recording, an embedded file of type `audio` or `video`, carries
that type as its stored type, so content of no signature route knows, a NUL in its head, is
routed by it. A page's ink is an SVG, routed vision-converted, to the picture stage's PNG. A skipped section is an
unread child at `skipped section <name>`: encrypted for a password-protected one, else failed.
that type as its stored type, so content of no signature route knows is routed by that type when
its head isn't text. A page's ink is an SVG, routed vision-converted, to the picture stage's PNG.
A skipped section is an unread child at `skipped section <name>`: encrypted for a
password-protected one, else failed.
- **audio.** No model runs: the stage prepares the windows a layer above transcribes and joins, and
the plan it joins them by. Each window is yielded as the part's one decode cuts it, in plan order,
`window N`, a 16 kHz mono 16-bit PCM WAV named by its SHA-256, its `Meta` carrying what a caller
Expand Down
15 changes: 9 additions & 6 deletions docs/limits.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ an unencrypted one that is not a text, spreadsheet, presentation, or drawing doc
such as a formula, chart, database, or image package (`.odf`, `.odc`, `.odb`, `.odi`), with no
processor yet. ISO routes to no stage. docproc runs no virus scan and flags no macro in an OLE2
file. Content no processor claims is read as text, whatever its name, when its first 4096 bytes hold
no NUL byte, and is unrouted when they do. So HTML and an EPUB's entries are read as raw text, with
no structure, and UTF-16 without a byte order mark, which holds NULs, is refused. docproc detects no
text's encoding: it reads text by its byte order mark, as UTF-8, or else as windows-1252, so a
legacy multibyte encoding such as Shift-JIS, EUC-JP, or ISO-2022-JP reads as mojibake. Beyond that,
each stage inherits its tool's limits, as the tools' READMEs
([docproc-ooxml](../tools/ooxml/README.md), [docproc-mail](../tools/mail/README.md),
no control byte and are either valid UTF-8 or windows-1252 without its five undefined bytes (0x81,
0x8D, 0x8F, 0x90, 0x9D), and is unrouted otherwise. A control byte is a C0 control other than tab,
line feed, form feed, or carriage return, or DEL. A UTF-8 rune cut off at the 4096th byte is allowed
when the content runs past it. So HTML and an EPUB's entries are read as raw text, with no
structure, while UTF-16 without a byte order mark, which holds NULs, and a log holding terminal
escapes are refused. docproc detects no text's encoding: it reads text by its byte order mark, as
UTF-8, or else as windows-1252, so a legacy multibyte encoding such as Shift-JIS, EUC-JP, or
ISO-2022-JP reads as mojibake. Beyond that, each stage inherits its tool's limits, as the tools'
READMEs ([docproc-ooxml](../tools/ooxml/README.md), [docproc-mail](../tools/mail/README.md),
[docproc-onenote](../tools/onenote/README.md)) state them in full; these are the ones a host sizes
or routes by.

Expand Down
2 changes: 1 addition & 1 deletion postgres/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ each system tool under `tools/` keep their own.

- The module's unit tests and integration suite sit in its `test/` directory as an external test
package. No exported API changes.
- The module requires the docproc base module at v0.12.0, from v0.11.0, and passes its
- The module requires the docproc base module at v0.13.0, from v0.11.0, and passes its
`dispatchtest.Index` suite; its [CHANGELOG](../CHANGELOG.md) states the base module's changes.

## [v0.1.9] - 2026-11-28
Expand Down
2 changes: 1 addition & 1 deletion postgres/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.27.4

require (
github.com/jackc/pgx/v5 v5.13.0
github.com/standards-lab/docproc v0.12.0
github.com/standards-lab/docproc v0.13.0
github.com/standards-lab/sqlate v0.8.0
github.com/standards-lab/sqlate/postgres v0.9.0
)
Expand Down
4 changes: 2 additions & 2 deletions postgres/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ github.com/jackc/puddle/v2 v2.2.3 h1:f8HoREISb3l5eO9coPgK7U3hKLhWGokOFVcThl5jrao
github.com/jackc/puddle/v2 v2.2.3/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/standards-lab/docproc v0.12.0 h1:fKof6WCaze3tu+sCI5cx3OgsH5s86Aus65DBsQNA0Mg=
github.com/standards-lab/docproc v0.12.0/go.mod h1:ZA8JYQPooA6YA84b00Lpu5AiSL2VSj/u7QnenltqVBA=
github.com/standards-lab/docproc v0.13.0 h1:WRvUFHvMM1eFxBr9sFkgRH7Co2GkW2jgrEvdflPY6Io=
github.com/standards-lab/docproc v0.13.0/go.mod h1:ZA8JYQPooA6YA84b00Lpu5AiSL2VSj/u7QnenltqVBA=
github.com/standards-lab/sqlate v0.8.0 h1:G1uUIWmc2DxJz5YhtBvIlftfURnb3b2RKsYB59Wa03Y=
github.com/standards-lab/sqlate v0.8.0/go.mod h1:pikNmGf/z3x46SBWFXgt/xKIDZuquSgCoXy5OWBFFR4=
github.com/standards-lab/sqlate/postgres v0.9.0 h1:l6PXEZ3GQM4+0zekxlSONhyHjpQU8g8StAS16bBqzZE=
Expand Down
24 changes: 16 additions & 8 deletions route/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// for a cabinet, and for content of no signature, which is a message by the .eml rule. A name's
// extension never makes content text, nor does a stored audio or video type make text media.
// Content no route claims, or that fails a claim's own check, falls back on its head: text when
// its first [HeadLen] bytes hold no NUL byte, and unrouted when they do, its reason the claim it
// its first [HeadLen] bytes are text, and unrouted when they aren't, its reason the claim it
// failed, or "no routed signature", then ", text by its head" or ", not text"; content named .eml
// or stored as a message whose header isn't a message's shape is the exception, its reason "a
// message by its <name or type>, but not header-shaped", then "; text by its head" when it is
Expand All @@ -34,6 +34,11 @@
// whole for an EncryptedPackage stream's directory entry, by [EncryptedPackage], which inspect
// calls too; an mbox is read past its "From " line for a message's header; and content of no
// signature is read for a message's header, a header after a UTF-8 byte order mark among them.
// A head is text when it holds no C0 control other than tab, line feed, form feed, or carriage
// return, and no DEL, and is either valid UTF-8 or windows-1252 without its five undefined bytes,
// 0x81, 0x8D, 0x8F, 0x90, and 0x9D; a rune the head cuts off at its end is valid when the content
// runs past the head. A byte order mark makes content text ahead of the test, so UTF-16 and UTF-32
// marked by one are text.
// The routes:
//
// - [Document]: a PDF, for the document package's stage.
Expand All @@ -57,19 +62,19 @@
// - [Archive]: a ZIP that is neither office's nor ODF, a tar, gzip, zstd, 7z, RAR4, RAR5, xz,
// or bzip2 archive, or a cabinet not named .onepkg.
// - [Audio]: WAV, FLAC, MP3, an Ogg that begins no video stream, or M4A; or content of no
// signature stored as an audio type whose head holds a NUL byte.
// signature stored as an audio type whose head isn't text.
// - [Video]: MP4, Matroska, WebM, AVI, an MPEG program stream, or an Ogg video; or content of
// no signature stored as a video type whose head holds a NUL byte.
// no signature stored as a video type whose head isn't text.
// - [Text]: content marked by a byte order mark; a script, by its "#!" line; and the
// fallback's content whose head holds no NUL byte, whatever its name or stored audio or video
// fallback's content whose head is text, whatever its name or stored audio or video
// type: HTML, CSS, JavaScript, an EPUB's entries, a .txt, .csv, or .json, a LICENSE, prose
// that begins "From " without a message header, or content named .eml or stored as a message
// whose header isn't a message's shape, but for an SVG, which routes by its root element.
// - [Unrouted]: a deliberate refusal: a PE, ELF, or Mach-O executable, whose reason names it an
// executable; an .ost, whose reason names it, since mail refuses one; an XPS package, a ZIP
// holding FixedDocumentSequence.fdseq, whole or as its first piece, whatever its name, ahead
// of the OOXML rules, since one is an OPC package too and may be named .docx; and the
// fallback's content whose head holds a NUL byte, an OLE2 compound file without a legacy or
// fallback's content whose head isn't text, an OLE2 compound file without a legacy or
// .msg extension, an mbox's "From " line without a message header, and content named .eml or
// stored as a message whose header isn't a message's shape among it.
//
Expand All @@ -91,9 +96,12 @@
// - [File] routes the file at a path, and says why; [At] routes content already open.
// - [MediaType] gives the media type of content as At routes it, on At's inputs: a [Kind]'s
// type by its signature; within a ZIP, an ODF package, or an OLE2 compound file, the name's
// extension first, for an OOXML, OpenDocument, or legacy office type, .msg's, or .zip's; and,
// for content of no signature, text/plain, message/rfc822, or application/octet-stream by
// its route.
// extension first, for an OOXML, OpenDocument, or legacy office type, .msg's, or .zip's; a
// HEIC's by its ftyp box's major brand, image/heic, image/heic-sequence, image/heif, or
// image/heif-sequence; and, for content of no signature, message/rfc822 or
// application/octet-stream by its route, or, for [Text], a type by the name's extension from
// route's own table, such as text/markdown for .md, text/csv for .csv, or application/json
// for .json, and text/plain for an extension outside it.
// - [Ext] reads a name's extension; [OOXMLExtension] reports whether it is an OOXML
// package's, the one table of them; [LegacyTarget] gives the OOXML format a legacy
// extension converts to, the one table of those; [EncryptedPackage] reports whether an OLE2
Expand Down
11 changes: 9 additions & 2 deletions route/identify.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,10 @@ func isRIFF(head []byte) Kind {
}

func isISOBMFF(head []byte) Kind {
if len(head) < 12 || string(head[4:8]) != "ftyp" {
major, ok := majorBrand(head)
if !ok {
return Unknown
}
major := brand(head[8:12])
boxLen := min(int(binary.BigEndian.Uint32(head)), len(head))
var compatible []string
for i := 16; i+4 <= boxLen; i += 4 {
Expand All @@ -452,6 +452,13 @@ func isISOBMFF(head []byte) Kind {
return MP4
}

func majorBrand(head []byte) (string, bool) {
if len(head) < 12 || string(head[4:8]) != "ftyp" {
return "", false
}
return brand(head[8:12]), true
}

func brand(b []byte) string {
return string(bytes.TrimRight(b, " \x00"))
}
Expand Down
46 changes: 42 additions & 4 deletions route/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ var kindTypes = map[Kind]string{
EMF: "image/emf",
WMF: "image/wmf",
SVG: "image/svg+xml",
HEIC: "image/heic",
WebP: "image/webp",
AVIF: "image/avif",
ZIP: zipType,
Expand Down Expand Up @@ -59,6 +58,31 @@ var kindTypes = map[Kind]string{
UTF32BOM: textPlain,
}

var heifTypes = map[string]string{
"heic": "image/heic", "heix": "image/heic", "heim": "image/heic", "heis": "image/heic",
"hevc": "image/heic-sequence", "hevx": "image/heic-sequence",
"heif": "image/heif", "mif1": "image/heif", "miaf": "image/heif",
"msf1": "image/heif-sequence",
}

var textTypes = map[string]string{
".md": "text/markdown",
".markdown": "text/markdown",
".csv": "text/csv",
".tsv": "text/tab-separated-values",
".html": "text/html",
".htm": "text/html",
".xml": "application/xml",
".json": "application/json",
".yaml": "application/yaml",
".yml": "application/yaml",
".css": "text/css",
".js": "text/javascript",
".mjs": "text/javascript",
".ics": "text/calendar",
".vcf": "text/vcard",
}

var zipTypes = map[string]string{
".zip": zipType,
".odt": "application/vnd.oasis.opendocument.text",
Expand All @@ -85,15 +109,26 @@ const outlookType = "application/vnd.ms-outlook"
// application/vnd.ms-powerpoint, or application/vnd.ms-outlook for .msg. Otherwise the [Kind]
// head's signature names decides, such as application/pdf for a [PDF], application/zip for a ZIP
// or an ODF package, application/x-ole-storage for an OLE2 compound file, application/mbox for an
// mbox, and text/plain for a script or a byte order mark. Content of no signature takes the route
// At gives it, with name and mimeType: text/plain for [Text], message/rfc822 for [Nested], and
// application/octet-stream otherwise. It returns an error only for r's own.
// mbox, and text/plain for a script or a byte order mark. A [HEIC] takes its type from its ftyp
// box's major brand: image/heic for heic, heix, heim, or heis; image/heic-sequence for hevc or
// hevx; image/heif for heif, mif1, or miaf; and image/heif-sequence for msf1. Content of no
// signature takes the route At gives it, with name and mimeType: message/rfc822 for [Nested];
// application/octet-stream for any route but [Text], whatever its name; and, for Text, a type by
// the name's extension, text/markdown for .md or .markdown, text/csv for .csv,
// text/tab-separated-values for .tsv, text/html for .html or .htm, application/xml for .xml,
// application/json for .json, application/yaml for .yaml or .yml, text/css for .css,
// text/javascript for .js or .mjs, text/calendar for .ics, and text/vcard for .vcf, or text/plain
// for any other. It returns an error only for r's own.
func MediaType(r io.ReaderAt, size int64, head []byte, name, mimeType string) (string, error) {
head = head[:min(len(head), HeadLen)]
kind := Identify(head)
if t := containerType(kind, Ext(name)); t != "" {
return t, nil
}
if kind == HEIC {
major, _ := majorBrand(head)
return heifTypes[major], nil
}
if t, ok := kindTypes[kind]; ok {
return t, nil
}
Expand All @@ -103,6 +138,9 @@ func MediaType(r io.ReaderAt, size int64, head []byte, name, mimeType string) (s
}
switch routed {
case Text:
if t, ok := textTypes[Ext(name)]; ok {
return t, nil
}
return textPlain, nil
case Nested:
return "message/rfc822", nil
Expand Down
Loading